例如,我希望导航中的此更改能够重新加载状态:
#/detail/1
#/detail/2
但是我不希望这个导航重新加载状态:
#/detail/1?search=blah
#/detail/1?search=huzzah
根据 ui-router 文档,设置 reloadOnSearch: false
应该可以完成此操作,但请尝试下面的方法。当 reloadOnSearch === false
时,更改路径参数不会重新加载状态,即使文档说它应该。
最佳答案
我创建了一个 plunker ,表明 ui-router
特征 reloadOnSearch
正在按记录工作 here :
reloadOnSearch:
Boolean (default true). If false will not retrigger the same state just because a search/query parameter has changed. Useful for when you'd like to modify $location.search() without triggering a reload.
所以,这就是说,如果我们确实有这样的状态
.state('index.detail', {
url: '/detail/:id',
reloadOnSearch : false,
...
})
导航到
-
ui-sref="index.detail({id:1})"
将加载此状态,同时导航到
-
ui-sref="index.detail({id:any-other-id})"
什么都不做。但!如果我们引入新的(例如 sibling ) 状态定义如下:
.state('index.other', {
url: '/other/:id',
reloadOnSearch : false,
...
})
导航到以下序列将始终重新触发状态重新加载,不是因为参数更改,而是因为状态更改
-
<a href="#/index/detail/1" ...
-
<a href="#/index/other/1" ... // will relaod
-
<a href="#/index/detail/2" ... // because the state
-
<a href="#/index/other/2" ... // is changing
查看所有操作 here ...
关于javascript - Angular ui 路由器 : how do I reload a state when a path parameter changes but not reload when a query parameter changes?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24622120/