可以使用Angular UI Router隐藏URL中的某些参数吗? [英] Possible to hide some parameters in URL with Angular UI Router?
问题描述
我想通过参数将两个值传递给新的ui-view:
I want to pass two values to new ui-view via params:
- 商品ID
- 对象列表
但是,我希望新视图仅在浏览器URL中显示id,而不显示字符串化的对象数组:
However, I'd like the new view to show only the id in the browser URL and not the stringified array of objects:
http://www.myapp.com/#/my-view/4
INSTEAD OF
http://www.myapp.com/#/my-view/4?flskdjalfjaewoijoijasdlfkjösldakjföliwejöorijo
是否可以a)传递隐藏在ui视图中的对象数组,或者b)传递两者但从浏览器URL中隐藏另一个对象?
Is it possible to either a) pass the array of objects hidden to the ui-view or b) pass both but hide the other from the browser URL?
我发现了有关squash参数的信息,但无法执行我正在尝试的操作.
I found something about the squash parameter, but couldn't get it to do what I'm trying.
这是我的观点:
$stateProvider
.state('show', {
url: "/show/{itemId}?{itemList}",
views: {
'mainView': {
templateUrl: 'views/itemView.html',
controller: 'showController',
params: {
itemList: {
value: null,
squash: true
},
itemId: -1
}
}
}
如何隐藏URL中的对象列表而不隐藏ID?
How can I hide the list of objects from the URL, without hiding the id?
推荐答案
您在正确的道路上.要隐藏参数,您必须像在params
中那样定义它们,而无需squash
.
You are on the right path. To hide params you have to define them in params
as you do, without squash
.
您的示例应如下所示:
$stateProvider
.state('show', {
url: "/show?itemId",
views: {
'mainView': {
templateUrl: 'views/itemView.html',
controller: 'showController'
// params do not work here! They need to be attached below ...
// $stateProvider.state('show', {url:'/show/:url_param',views:{}, params: {}})
}
},
resolve: {},
params: {
itemList: {
value: null
}
}
})
请参阅示例: http://plnkr.co/edit/wEjwCVWMKTyuSdyLr0og?p=preview
这篇关于可以使用Angular UI Router隐藏URL中的某些参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!