0

I've tried the solution here: https://www.consolelog.io/angularjs-change-path-without-reloading/

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]);
    };
}])

But the path I set it to just gets consumed and reverts back to how it was.

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Yomboioi
  • 11
  • 2

1 Answers1

0

The default behavior of the ngRoute router is to reload the ngView when the path changes and the new URL maps to the current route.

If the reloadOnSearch option is set to false, ngRoute will not reload the route when only $location.search() or $location.hash() changes:

app.config(function($routeProvider) {
    $routeProvider.when("/foo", {
        templateUrl: 'foo.html',
        controller: 'fooController',
        reloadOnSearch: false
    });
})

And the app invokes:

$location.hash({pageNumber: n});

A $routeUpdate event is broadcast on the root scope (without reloading the route).1

georgeawg
  • 48,608
  • 13
  • 72
  • 95