In my application I need to create unique URL's for users. Currently I have the URL like this http://example.com/#/user/USER_NAME. But I need to modify this URL like http://example.com/#/USER_NAME. But I think this may create issues in the router. I anyone have a solution please help.
1 Answer
No, you won't get any problems if you use that approach. You just have to be carefull in how you define your route.
For instance:
$routeProvider.
when('/:username', {
templateUrl: 'templates/user.html',
controller: 'UserController'
}).
when('/home', {
templateUrl: 'templates/home.html',
controller: 'HomeController'
});
The home route will never get called in the above example, because /:username will match everything. So if you have multiple routes you just have to make sure the /:username route is the last route used.
$routeProvider.
when('/home', {
templateUrl: 'templates/home.html',
controller: 'HomeController'
}).
when('/:username', {
templateUrl: 'templates/user.html',
controller: 'UserController'
});