-
Notifications
You must be signed in to change notification settings - Fork 499
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
fix(routing): fix history router based on history length #5004
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit de02dca:
|
Thanks for your reviews! I think it makes sense to document these two behaviors @sarahdayan mentioned: Routing with debounced (more than 400 ms) third-party client-side router does not clean the URL after navigating
Routing using
|
Where would you document that behaviour? https://www.algolia.com/doc/api-reference/widgets/history-router/js/#about ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎸
I think it could make sense in that page indeed, WDYT @sarahdayan? |
@FabienMotte Yes, we can document it here and have warnings that link to it in the routing guides that use the |
Summary
This PR solves the issue with the history router when the InstantSearch.js is disposed:
The fix has been suggested by @Haroenv and it's based on the
window.history.length
. It allows to determine if awindow.history.pushState
has been triggered elsewhere, and thus to prevent thewrite
(called whendispose
is called on the InstantSearch.js instance) method from callingwindow.history.pushState
.Result
As a result, in a SPA use case, the history stack is correct and the browser back button works as expected. In a modal use case, when the InstantSearch.js instance is disposed, the URL is cleaned as expected.
SPA use case: https://codesandbox.io/s/vue-instantsearch-spa-fixed-fsdno
Modal use case (not changed): https://codesandbox.io/s/instantsearch-js-modal-zg12q