Change route parameters without updating view

后端 未结 3 1767
温柔的废话
温柔的废话 2020-12-24 14:16

I\'m currently trying to figure out how to change the route parameters without reloading the entire page. For example, if I start at

http://www.example.com/#/page

3条回答
  •  借酒劲吻你
    2020-12-24 14:42

    I actually found a solution that I find a little more elegant for my application.

    The $locationChangeSuccess event is a bit of a brute force approach, but I found that checking the path allows us to avoid page reloads when the route path template is unchanged, but reloads the page when switching to a different route template:

    var lastRoute = $route.current;
    $scope.$on('$locationChangeSuccess', function (event) {
        if (lastRoute.$$route.originalPath === $route.current.$$route.originalPath) {
            $route.current = lastRoute;
        }
    });
    

    Adding that code to a particular controller makes the reloading more intelligent.

提交回复
热议问题