在 ui-router url 中查询字符串参数? [英] 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
时,?customer 查询字符串被剥离,我留在 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.
对我来说最有意义的只是将 params: ['customer']
添加到 quotes.new
状态定义中,但这给了我一个错误抱怨我指定了 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-router url 中查询字符串参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!