在ui路由器网址中查询字符串参数? [英] Query string parameter in ui-router urls?
问题描述
我有以下状态:
.state('quotes', {
abstract: true,
url: '/quotes'
})
.state('quotes.new', {
url: '/new',
templateUrl: 'views/quote-form.html',
controller: 'QuoteFormCtrl'
})
.state('quotes.new.customer', {
url: '?customer',
templateUrl: 'views/quote-form.html',
controller: 'QuoteFormCtrl'
})
当我点击URL /quotes/new?customer=123
时,剥离了客户查询字符串,而我仍然处于quotes.new
状态.
When I hit the URL /quotes/new?customer=123
the ?customer query string is stripped off, and I am left at the quotes.new
state.
对我来说最有意义的只是在quotes.new
状态定义中添加params: ['customer']
,但这使我犯了一个错误,抱怨我同时指定了url和params.
What would make most sense to me is just adding a params: ['customer']
to the quotes.new
state definition, but that gives me an error complaining that I specify both url and params.
任何关于我正在尝试做的事的例子都将不胜感激.
Any examples of what I'm trying to do would be much appreciated.
推荐答案
您应该修改url
字符串属性以包括您的customer
查询参数,如下所示:
You should modify the url
string property to include your customer
query parameter, like this:
.state('quotes.new', {
url: '/new?customer',
templateUrl: 'views/quote-form.html',
controller: 'QuoteFormCtrl'
});
可以通过使用&
分隔多个参数来添加多个参数:
Multiple parameters can be added by separating them with an &
:
.state('mystate', {
url: '/myState?paramOne¶mTwo
//...
});
请参见文档
这篇关于在ui路由器网址中查询字符串参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!