Control over history method #357
ethmcc
started this conversation in
Feature ideas
Replies: 1 comment
-
|
Since swup 3.1, you can tell swup to replace the history entry instead of creating a new one: <a href="/about" data-swup-history="replace">About</a> |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
First of all, thanks for the great work on this product! I have an idea for a feature I wonder if you'd consider:
When developing websites, I often have routes which are intended mainly to update content on the current page and redirect back to the current page.
Consider something like this pseudocode Flask route:
If I'm visiting my site's
/route and click on a link for/update/<item_id>, Swup will helpfully push a history entry, because it sees that I'm navigating to a different page. But it would be nice if I could override that behavior in cases like this, where I know the route will redirect to the current page.I have made a fork and whipped together something basic for my needs (expand for details):
In this implementation, if
loadPageis called withnoPushHistoryset indata, then thecreateHistoryRecordsubroutine is skipped. To use this option in normal use outside of direct API calls toloadPage, the user setsoptionPushHistory : truein options, then when a link is clicked the fork checks if the link has an attributedata-swup-no-push-historyand callsloadPagewith or without thenoPushHistoryoption as appropriate.If
loadPageis called as normal withoutnoPushHistory, or if Swup is initialized without theoptionPushHistoryoption, then they behave as usual.https://github.com/ethmcc/swup/commit/855945...
My apologies if there is already some easy way to accomplish this sort of thing using the API as-is, I couldn't see any way to do it. And similarly I couldn't see any way to implement this feature through the existing plugins framework.
Beta Was this translation helpful? Give feedback.
All reactions