AngularJs ui-router $location or $state?

左心房为你撑大大i 提交于 2019-12-07 18:43:53

问题


How can I transform this:

$location.path('/app/home/' + id).search({x:y});

to this:

$state.go('/app/home/' + id).search({x:y});

I tried, but I actually can't get enough information how to achieve that...


回答1:


There is nice documentation (while deprecated, still really clear):

$state.go(to [, toParams] [, options])

Let's say that the state definitions are looking like this:

.state('app', { // parent app
  url: '/app',
  ...
})
.state('app.home', {
  url: '/home/:x',         // the param named x
  ...

Then you will do

$state.go('app.home', {x:y});

This Q&A could help as well:

  • Angular ui-router - how to access parameters in nested, named view, passed from the parent template?


来源:https://stackoverflow.com/questions/26138140/angularjs-ui-router-location-or-state

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!