Hi All
I want to learn how to use the can router better and how are other
solving the following.
I have an app that have routes like:
/#users // Show list of users
/#users/1 // show user 1
/#users/search?foo=bar // search for users
/#users/1/comments // all comments for user
/#users/1/comments/new // form for adding a new comment for user 1
/#users/1/comments/search?foo=bar // search comments for user 1
At the moment I simply write the links in my templates e.g. '/#users/{{user.id}}/comments/new'
I have the flexibility of making my routes whatever I want but it
is not great as the application could break if the routes changes.
Both Ember and React-Router (https://github.com/rackt/react-router)
use named routes to solve this issue. You write links like:
<link to="new_user_comment" params="{userId:
user.id}" /> or something like this. This will generate /#users/1/comments/new
However in CanJS I haven't found a clear way to generate the routes
I want, thus I just hardcode them.
CanJS has the concept of pretty url using a template, but it seems
to me that they are useful if your whole application follows a very
strict pattern e.g. /:resource/:id/:action, but as soon as you want
something different this system doesn't work anymore.
So my question is, what are your solutions for this? Is it possible
to do these routes neatly with what is already in can.router?
Personally I think that CanJS could benefit by having a router with
named routes like React-Router.