使用ui-router和transitionservice触发url刷新

问题描述 投票:0回答:1

嗨,我有 ui-router 的问题。我的网址已被替换,但页面未重新加载。 我使用“@uirouter/angularjs”:“^1.0.26”,“Angular”:“~1.5.11”,

我的代码在我的 $stateProvider 解析中

$transitions.onSuccess({}, function (transition) {

options.forEach((options) => {
    api
        .load()
        .then((response) => {
            if (response) {
                const currentUrl = $location.absUrl();
                let updatedUrl = currentUrl;
                response.data.forEach((element) => {
                    if (element) {
                        const regex = new RegExp(`'${element}~`);

                        if (updatedUrl.match(regex)) {
                            updatedUrl = updatedUrl.replaceAll(
                                `'${element.data}~`,
                                `'${element.data.plam}~`
                            );
                        }

                    }
                });
                if (updatedUrl !== currentUrl) {
                    $timeout(function() {
                        $window.location.href = updatedUrl;
                    });
                }

            }
        });
});

});

javascript angularjs angular-ui-router
1个回答
0
投票

我使用两者解决了我的问题

$window.location.href = updatedUrl;  

$window.location.reload();
© www.soinside.com 2019 - 2024. All rights reserved.