Angular - UI Router - state reentrance

只谈情不闲聊 提交于 2019-12-13 15:58:41

问题


How to config UI Router to reenter or reload the state by default?

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.

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?

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.


回答1:


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;
    });
});


来源:https://stackoverflow.com/questions/24928039/angular-ui-router-state-reentrance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!