CodeYellowBV / tarantino

a tiny and isomorphic URL router for JavaScript.
MIT License
11 stars 3 forks source link

replaceRoute API support request? #9

Open albertalquisola opened 7 years ago

albertalquisola commented 7 years ago

Any chance we can get support for a call that looks something like this?

// does not add an entry into the browser history
router.replaceRoute('/new/route');

Under the hood, director is using window.pushState() on the router.setRoute() call which will push a new entry onto the window history stack. This makes the native browser history inflexible in certain cases.

eg. if i only want to change query params (user isn't taken to new page) previous url: example.com/home current url: example.com/new/route router.setRoute('/new/route?new=true');

Now, if the user clicks back button, they'll be taken to example.com/new/route which is the same page sans any query param filter. I would like the control to navigate them back to example.com/home instead.

Also, this has been requested by a few of people: https://github.com/flatiron/director/issues/316

SpaceK33z commented 7 years ago

Fair enough. Would you be interested in making a PR?

albertalquisola commented 7 years ago

Potentially. However, I'm not overly familiar with how to replicate this behavior in legacy browsers (browsers that dont support window history API)

albertalquisola commented 7 years ago

I went ahead and wrote a quick implementation for replaceRoute. Mind adding me as a collaborator so I can submit a PR? I cant push my branch up due to insufficient permissions.

SpaceK33z commented 7 years ago

That shouldn't be necessary, if you go to the Pull Requests page in this repo, you can click "New pull request" and select your own fork.

albertalquisola commented 7 years ago

cool, thats fine. just submitted a PR. This is more a proof of concept. If you like the approach, I can refine/refactor a bit more and add test cases