Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
can.route - Allow changing the route (and URL) without saving to browser history #1137
I'm working on a relatively complex 'single page' app which implement its own client-side page switching (with transitions).
I researched can.route and the pushstate plugin but I wasn't able to find a way to use can.route to change the hash part of the URL without affecting the history.
A user is on a page and they click a button which causes part (but not all) of the page's content to be updated with new data. They might click through many such buttons. Now if they press the back button, I want to take them back to the previous 'proper' page - Not the previous state (there might be a LOT of such states not related to page changes and it would be tedious to make them click back 50 times to get to the actual 'previous page' - Especially if they navigate back and forth between buttons). When they click on a button, I still need to update the URL in case they want to bookmark the app's exact state or share it with someone else.
I had to add some workaround code that made use of history.replaceState() to get this behaviour working - It would be great if there had been an option you could set when calling can.route.attr(attrName, value) which would let you not save that particular route to history (but otherwise should behave the same).
Maybe this already exists but I wasn't able to find any documentation.
What would this look like? Please propose an API.
Sent from my iPhone
@justinbmeyer - Maybe something along the lines of can.route.attr(key, value[, options]) - The options object could hold property names (I.e.. a 'history' property in this case) to let you customize how can.route should handle the attribute change.
// Overwrite the previous history entry
// Do not add this route to history at all
I realize that this somewhat violates the simplicity (and consistency) of the attr() method so maybe it's not ideal. But then again, functionality-wise, can.route's attr() method does more than that of can.Map, so maybe having an extra argument is justified?
The other alternative I can think of is to add a can.route.navigate(attrName, value, history)
In keeping with how can.route is supposed to work, having a different
It seems to me that "some" changes you'd want to have the history change and others not. Maybe it's possible to signal this some other way.
I'm not proposing this API, but just to show you what I mean:
This would use replaceState if those attributes changed.
Any thoughts on this?
Actually yes, something like that should work well.
Alternatively, the history-tracking status of each route could be a config option passed to can.route(). I think generally, the history behavior won't change at runtime anyway. Both techniques are equivalent for my particular use case.