I currently have a routes object that has several regular pages, and would like also to add a top-level route in which the first parameter is a username.
routes : {
'/' : 'main',
'/login' : 'login',
'/about' : 'about',
'/create' : 'create',
'/:username': 'getUser' //something like this
'*actions' : 'defaultHandler'
}
- how would i achieve this?
- would it be bad design to add the username route while also falling back on actions when no page or user is found?
What happens when you have a user called “about” or “create”? Namespace your routes and avoid the problem:
Then you just have to make sure no one has “a” as a username. This approach also protects you against future conflicts if you add more routes.