1

My routing is:

$stateProvider.state('login', {
  url: '/login'
  views:
    appView:
      templateUrl: '/templates/login.html'
}).state('chooser', {
  url: '/chooser'
  views:
    appView:
      templateUrl: '/templates/chooser.html'
}).state('admin', {
  url: '/admin'
  views:
    appView:
      templateUrl: '/templates/admin.html'
}).state('admin.users', {
  url: '/admin/users'
  views:
    appView:
      templateUrl: '/templates/admin.html'
    adminView:
      templateUrl: '/templates/admin-users.html'
})

In my view, I have:

  <ul class="nav nav-pills nav-stacked">
    <li><a ui-sref="admin.users">Users</a></li>
    <li><a href="#">Profile</a></li>
    <li><a href="#">Messages</a></li>
  </ul>

When I click the link for Users it goes to /admin/admin/users instead of /admin/users. What am I doing wrong?

2 Answers 2

1

A child state does inherit the parent url. So the mapping should look like this:

.state('admin.users', {
  //url: '/admin/users'
  url: '/users'
  views:
    appView:
      templateUrl: '/templates/admin.html'
    adminView:
      templateUrl: '/templates/admin-users.html'
})

And the resulting url will be /admin/users

The other option is to restart url evaluation, see: Absolute Routes (^):

If you want to have absolute url matching, then you need to prefix your url string with a special symbol '^'.

.state('admin.users', {
  //url: '/admin/users'
  url: '^/admin/users'
  views:
    appView:
      templateUrl: '/templates/admin.html'
    adminView:
      templateUrl: '/templates/admin-users.html'
})
Sign up to request clarification or add additional context in comments.

Comments

1

the state should be as follow as state inherits routes. change it as follow:

.state('admin.users', {
    url: '/users'
    views:
     appView:
       templateUrl: '/templates/admin.html' 
     adminView:
       templateUrl: '/templates/admin-users.html'
})

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.