Angular - UI 路由器 - 状态重入 [英] Angular - UI Router - state reentrance
问题描述
如何配置 UI Router 默认重新进入或重新加载状态?
例如用户想要刷新页面,所以他点击了该页面的链接.但目前该链接不可点击,因为它转到同一页面并且状态不会改变.使用浏览器按钮刷新确实有效,因此它会再次重新加载整个 SPA - 不可取.
E.g. user wants to refresh page, so he clicks the link that follows to that page. But currently the link isn't clickable, as it goes to the same page and the state doesn't change. Refreshing with browser button does work, so it reloads entire SPA again - isn't desirable.
这个问题-重新加载当前状态-刷新数据 - 描述类似的效果.是否可以更改此解决方案 - https://stackoverflow.com/a/23198743/404099 - 定义默认值行为?
This question - Reloading current state - refresh data - describes similar effect. Is it possible to change this solution - https://stackoverflow.com/a/23198743/404099 - to define the default behavior?
顺便说一句,可能我的方法不正确,我在 UI 路由器中缺少一些基本的想法.请指出是否是这种情况.
By the way, probably my approach is incorrect and I'm missing some basic idea in UI Router. Please point out if this is the case.
推荐答案
我赞同 @Sabacc 所说的,但如果你仍然如此,那么你去吧:
I second what @Sabacc said, but if you still instead, here you go:
angular.module('app')
.config(function($provide) {
$provide.decorator('$state', function($delegate)
{
$delegate.go = function(to, params, options)
{
return $delegate.transitionTo(to, params, angular.extend(
{
reload: true,
inherit: true,
relative: $delegate.$current
}, options));
};
return $delegate;
});
});
这篇关于Angular - UI 路由器 - 状态重入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!