visionmedia / page.js

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

Stopping and starting page.js has some odd results. #567

Open arne-strout-icrossing opened 3 years ago

arne-strout-icrossing commented 3 years ago

The use case would be to re-dispatch if a user is already on a url that matches the route you just added to page.js but your code to add the handler ran after page.js started. In other threads the solution suggested has been to perform a page.stop() followed by page.start().

This works, but in a very specific situation it fails (at least for me). Here's a psuedo implementation:

page('/myroute/*',(context,next)=>{
   if(next)next();
});
page.start()
page('/myroute/other/*',(context,next)=>{

    if(next)next();
});

page.stop();
page.start();

page('/myroute/other/beans');
// this will reload the page at the url mydomain/myroute/other instead of updating the url

Not sure as to why this is happening, something not being cleaned up when start() is subsequent to stop() maybe? I solved by removing if(next)next(); from my second handler, but that shouldn't be necessary.