将查询字符串添加到UI路由器路由 [英] Adding query string to UI router route
问题描述
我有一个定义如下的ui路由器路由
I have a ui router route that is defined as follows
$stateProvider
.state('search', {
url: '/search',
abstract: true,
parent: 'loggedIn',
views: {
wrapper: {
controller: 'MyCtrl',
controllerAs: 'myCtrl',
templateUrl: '/scripts/views/search/views/search.wrapper.html'
}
}
})
.state('search.subs', {
url: '',
resolve: {
isLoggedIn: isLoggedIn
},
views: {
body: {
controller: 'SearchBodyCtrl',
controllerAs: 'searchBodyCtrl',
templateUrl: '/scripts/views/search/views/search.body.html'
}
}
});
无论如何,问题是我无法生成查询参数,因此url看起来像我尝试使用$state.transitionTo('search.subs', {hello: 'world'})
的/search?hello=world
一样,但这没有用.我发现我传递的所有不匹配的参数都将被放在查询字符串中,但事实并非如此.
Anyways the issue is that I cannot generate a query parameters so that the url looks like /search?hello=world
I tried using $state.transitionTo('search.subs', {hello: 'world'})
but that didn't work. I figured any params I passed that did not match would just be put in the query string but that is not the case.
推荐答案
这应该做您想做的事情:
This should do what you want to do:
.state('search.subs', {
url: '?hello', // This appends to the parent url
....
之后,您只需使用$state.go('search.subs', { hello : 'world' })
即可转换到search.subs状态.
Afterwards you can just use $state.go('search.subs', { hello : 'world' })
to transition to the search.subs state.
https://github.com/angular- ui/ui-router/wiki/URL-Routing#query-parameters
这篇关于将查询字符串添加到UI路由器路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!