0

I've implemented the solution explained here https://stackoverflow.com/a/24102139/2795097

app.run(['$route', '$rootScope', '$location', function ($route, $rootScope, $location) {
var original = $location.path;
$location.path = function (path, reload) {
    if (reload === false) {
        var lastRoute = $route.current;
        var un = $rootScope.$on('$locationChangeSuccess', function () {
            $route.current = lastRoute;
            un();
        });
    }
    return original.apply($location, [path]);
};
}])

Changing the path with no reload is working nicely with this solution.

It's afterwards when I'm having problems with links <a href='...'> managed with $routeProvider. They should reload the view but what actually happens is the path is changing, but my view is not updating at all. Bizarrely, some links actually refresh the view, some others don't.

That only happens after navigation by calling the new method from the solution $location.path with false.

Any idea what's happening here?

Community
  • 1
  • 1

1 Answers1

0

I had to add a small delay to unregister the $locationChangeSuccess function. My code ended like this:

 var original = $location.path;

$location.path = function (path, reload) {
if (reload === false) {
    var lastRoute = $route.current;
    var un = $rootScope.$on('$locationChangeSuccess', function () {
        $route.current = lastRoute;

    });

    $timeout(un, 200);
}

return original.apply($location, [path]);

};