使用ui路由器在AngularJS中的浏览器后退/前进按钮上重新加载页面

kdu*_*kdu 7 javascript angularjs html5-history angular-ui-router

我在我的angularjs应用程序中为ui路由器状态配置了以下配置.

    $locationProvider.html5Mode(true);
    $stateProvider
        .state('index', {
            url: '/index?zoom&center',
            views: {
                'map': {
                    controller: 'MapCtrl',
                    templateUrl: 'map.html'
                }
            },
            reloadOnSearch:false
    });
Run Code Online (Sandbox Code Playgroud)

但是,浏览器中的后退按钮会转到不同的URL,但我需要使用url作为stateParams重新加载页面.

例如:User1转到页面http://www.example.com/index?zoom=2¢er=1,2.然后他在页面中进行操作,网址变为http://www.example.com/index?zoom=12¢er=3,4

然后他按下后退按钮,url更改为上一个,但我需要重新加载我的页面让控制器读取查询参数才能做正确的事情......

任何方式让它与浏览器后退/前进一起工作?

Ale*_*xMA 1

您尝试过设置reloadOnSearch为 true 吗?如果这不适合您的需求,也许可以看看这个问题:Force AngularJS to reload a route while option reloadOnSearch is set to false

一个更简单的替代方案可能是在必要时使用 window.location = newUrl 强制重新加载。