visionmedia / page.js

Micro client-side router inspired by the Express router
http://visionmedia.github.com/page.js
7.68k stars 688 forks source link

How to use pushState to set url with page.js api? #420

Closed dman777 closed 6 years ago

dman777 commented 7 years ago

How can I use page.js api's to set the pushState so that I can set the url query params without reloading the page?

The below works on initial page load with /search-listings but after that, I can not get the url to change with pushState:

page('/search-listings', function(context) {
  window.history.pushState(null, null, '/search-listings?foo=bar')
  console.log('aaaaa'); 
  app.route = 'search-listings';
});
paulocoghi commented 6 years ago

You do not need to call the pushState function because page.js already does this automatically.

paulocoghi commented 6 years ago

@matthewp , this can be closed ;)

matthewp commented 6 years ago

There's also page.replace which we should probably document...

matthewp commented 6 years ago

Yep, thanks!