Angular - UI Router - state reentrance

2019-07-19 19:36发布

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条回答
Animai°情兽
2楼-- · 2019-07-19 19:53

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;
    });
});
查看更多
登录 后发表回答