Successfully Call history.pushState() from Angular Without Inifinite Digest?

后端 未结 4 1360
野的像风
野的像风 2021-01-17 16:46

Is there a way to call history.pushState() without angular going into an infinite digest loop?

I\'m trying to migrate my app from backend routing to fro

4条回答
  •  忘掉有多难
    2021-01-17 17:00

    I recently encountered a variation of this problem myself and none of the answers here worked for me in isolation. history.pushState was defined, but only worked if called from the console. I was able to come up with a solution by consolidating a few of the answers here. Here is the code I used to solve this problem:

    // Configure $locationProvider html5Mode
    app.config(['$locationProvider', function($locationProvider) {
        $locationProvider.html5Mode({ enabled: true, requireBase: false, rewriteLinks: false });
    }]);
    
    // In controller
    $window.history.pushState(null, 'Page Title', '/some_new_url');
    

    I'm running Angular 1.5.5.

提交回复
热议问题