-
Notifications
You must be signed in to change notification settings - Fork 414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manually push history with action advance #518
Comments
Try pushing with the current state:
|
@acetinick did you manage to solve this? @jaryl I've tried doing the following Turbo.StreamActions.my_push_state = function () {
const url = new URL(this.getAttribute("url"));
Turbo.navigator.history.push(url);
history.pushState(history.state, "", url);
console.log("my_push_state", url, history.state);
}; My use case looks like a list of products and filter form. Whenever user triggers form submit I receive a stream response that updates the content of a page and page URL (to something shareable): <turbo-stream action="replace"><template>...list of products</template></turbo-stream>
<turbo-stream
action="my_push_state"
url="http://localhost:3000/?foo=bar"
></turbo-stream> It almost works. URL is being updated but when the back button is pressed the following error is dropped to the console:
I'm not sure what I'm doing wrong here. What I want is to let the user return to original content before stream response changes were made. |
I've opened a separate issue for that #792 |
I have a situation where I would like to push a history item when I open modal window using a stimulus controller. I have this so far from looking at the code to try push history
window.Turbo.navigator.history.push(new URL(url))
This works good for replacing the URL and adding history state to the browser, however when you click the back button in the browser it replaces with the old URL but doesn't visit it. I would also like the back button to work similar to the way we can use data: { turbo_action: "advance" } on a regular tag. I know this is based on the work that @seanpdoyle worked on, is there perhaps a way to manually push history and make it still work with back button ?
The text was updated successfully, but these errors were encountered: