Is it possible to change $ location without starting the associated $ route

Is it possible to change the location path in Angular.js without starting the associated route. Perhaps something like the following (not working code):

$location.path("/booking/1234/", {silent: true}) 
+4
source share
3 answers

You can set reloadOnSearch to false in your router, and you can change the "search" part of the URL.

The idea is that you should design your URL scheme in such a way that when you change the base url, it represents another resource and should be rebooted. If the search part changes (the part after ? You can simply change the filter or sort order or something else).

+1
source

Yes, a workaround is possible.

 var off = $scope.$on('$stateChangeStart', function (e) { e.preventDefault(); off(); }); $location.path("/booking/1234/"); 

The way it works is to cache the next state change event - to make it not happen (by calling preventDefault and then calling to unregister this event handler).

Tested only on Chrome. Saw this in this post: https://github.com/angular-ui/ui-router/issues/64

Hope this helps

0
source

Here is the solution compiled in the angular module - https://github.com/garakh/ngSilent just add the module and then use this method:

 $ngSilentLocation.silent('/new/path/'); 
0
source

Source: https://habr.com/ru/post/1440297/


All Articles