javascript - overwrite $location pushState history AngularJS -
if returning user "results page" want see last filters used. using ngcookies
update last used search parameters on page.
controller('results', ['$location','$cookies',function($location,$cookies){ $location.search(angular.fromjson($cookies.search)); }]); //will yield: /results?param1=dude¶m2=bro
however, if click "back" not brought last page expect.
that's because state pushed onto history unperceived user.
the user landed on /results
controller pushed /results?param1=dude¶m2=bro
onto state history.
how overwrite or delete state /results
"back" return me user expect last page came be?
chain replace()
onto end of $location.search call:
controller('results', ['$location','$cookies',function($location,$cookies){ $location.search(angular.fromjson($cookies.search)).replace(); }]);
this causes last history entry replaced, rather new 1 added.
there reloadonsearch option can set false
prevent reloading route when search params change (if want button go /results
).
Comments
Post a Comment