To change path URL with AngularJS, $location. Path () are passed the new URL as a parameter, and the page is automatically re Loaded. This means so if you ever make a change to the URL of the Angular application, then the partial and controller would be re Loaded automatically. This was great most of the time, however, there was times when reloading the controller was unwanted. AngularJS doesn ' t had a native fix to stop reloading when the path was changed. So a quick addition to our App.js file would do the trick.
Solution
The solution is essentially to add a extra parameter to $location. Path (). So rather than just taking in the new URL, it'll also take in a Boolean were true would refresh the page and false would n Ot. The following block of code is a needs to be added to the App.js file.
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]);} ])
There you go, now here's what it'll look like in the controller where the path is being changed.
$location. Path ('/sample/' + $scope. Checkinid, False);
Well, that's all there was to it, we're now, and the change path of the the URL without reloading the page. If you had any questions, comments or suggestions feel free to leave a comment!
AngularJS Change Path without reloading