1

I've got a route:

.state('home.blog', {
  url: "/blog",
  templateUrl: "blog.html",
  controller: "BlogController"
})

And my route is localhost:3000/home/blog I would like to change it to localhost:3000/blog. I searched the Internet but I have not found any simple solution.

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335
Jakub
  • 45
  • 7

1 Answers1

5

This is because the url part is dervied from parent. But we can explicitly set, that parent should not be used by '^':

.state('home.blog', {
  url: "^/blog",
  templateUrl: "blog.html",
  controller: "BlogController"
})

See the doc

Absolute Routes (^)

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

$stateProvider
  .state('contacts', {
     url: '/contacts',
     ...
  })
  .state('contacts.list', {
     url: '^/list',
     ...
  });
Radim Köhler
  • 122,561
  • 47
  • 239
  • 335