0

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
  • "But I think this may create issues in the router", Why? Or, what issues are you currently facing? Commented Mar 13, 2014 at 15:12

1 Answer 1

1

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'
          });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.