Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change $location search preventing push to history

Tags:

angularjs

I have a router view with reloadOnSearch: false, it is a search page.

When entering without any search parameter I attempt to set some defaults:

entering in: #/search

I set defaults pars: #/search?currpage=1&pagesize=20
using $location.search({currpage:1,pagesize:20}) the job is done, but I also get the new url pushed in the history, which is as expected, but in this special case it breaks the logic of the navigation flow (clicking back button gets to #/search and again sets defaults and pushes)

Is there a way to replace the search string preventing the history push?

like image 991
aleclofabbro Avatar asked Sep 05 '14 11:09

aleclofabbro


1 Answers

Have you tried to you use the dedicated replace() method ? It prevent to add an history record :

$location.search({currpage:1,pagesize:20}).replace()

Never used it after a $location.search() but it definitely works on $location.path()

like image 143
Jscti Avatar answered Oct 29 '22 21:10

Jscti