Reload page on browser button back / forward in AngularJS with ui router

I have the following configuration for the ui router state in my angularjs application.

$locationProvider.html5Mode(true); $stateProvider .state('index', { url: '/index?zoom&center', views: { 'map': { controller: 'MapCtrl', templateUrl: 'map.html' } }, reloadOnSearch:false }); 

However, the rewind button in the browser goes to a different url, but I need to reload the page with urls like stateParams.

For example: User1 go to http://www.example.com/index?zoom=2¢er=1,2 . then it performs a grouping operation on the page, the url becomes http://www.example.com/index?zoom=12¢er=3,4

Then he presses the back button, the url changes to the previous one, but I need to reload my page so that the controller can read the request parameters to do the right thing ...

Any way to let it work with the browser back / forward?

+6
source share
1 answer

Have you tried setting reloadOnSearch to true? If this does not meet your needs, perhaps check this question: Force AngularJS to reload the route, although the reloadOnSearch option is set to false

A simpler alternative may be to simply force a reboot using window.location = newUrl when necessary.

+1
source

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


All Articles