在ui路由器网址中查询字符串参数? [英] Query string parameter in ui-router urls?

查看:61
本文介绍了在ui路由器网址中查询字符串参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下状态:

.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&paramTwo
  //...
});

请参见文档

这篇关于在ui路由器网址中查询字符串参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆