2017-04-13 91 views
0

假设我有一个具有爆炸对象作为查询字符串参数的url:“domain.com/example?id=1234 & params [a] = hello & params [ b] =世界& params [foo] = bar //等等等等等等“使用UI处理动态查询字符串参数设置路由器

如何配置角度ui路由器接受这个动态的查询字符串参数集?

.state('example', { 
    url: '/example?id&params[*]' ?? 
    ... 
}); 

回答

0

在这里,看起来你的params是一个关联数组。

可以此链接查看根据这个答案https://stackoverflow.com/a/29792020/1907391

在0.2.13版本christopherthielen

.state('foo', { 
    url: '/foo/:param1?param2', 
    params: { param3: null } // null is the default value 
}); 
$state.go('foo', { param1: 'bar', param2: 'baz', param3: { id: 35, name: 'what' } }); 
$stateParams in 'foo' is now { param1: 'bar', param2: 'baz', param3: { id: 35, name: 'what' } } 

而且也,你应该能够物体进入$状态https://github.com/angular-ui/ui-router/issues/983 评论。去,

$state.go('myState', {myParam: {some: 'thing'}}) 

$stateProvider.state('myState', { 
       url: '/myState/{myParam:json}', 
       params: {myParam: null}, ... 
and then access the parameter in your controller. 

$stateParams.myParam; 
相关问题