AngularJs ui-router $ location还是$ state?

its*_*sme 2 javascript state angularjs angular-ui-router

我怎样才能改变这个:

$location.path('/app/home/' + id).search({x:y});
Run Code Online (Sandbox Code Playgroud)

对此:

$state.go('/app/home/' + id).search({x:y});
Run Code Online (Sandbox Code Playgroud)

我尝试过,但实际上我无法获得足够的信息如何实现...

Rad*_*ler 11

有很好的文档(虽然已弃用,但仍然非常清楚):

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

假设state定义看起来像这样:

.state('app', { // parent app
  url: '/app',
  ...
})
.state('app.home', {
  url: '/home/:x',         // the param named x
  ...
Run Code Online (Sandbox Code Playgroud)

然后你会做

$state.go('app.home', {x:y});
Run Code Online (Sandbox Code Playgroud)

此问答也可以提供帮助: