This repository has been archived by the owner on Apr 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Router doesn't monitor pushState/replaceState #54
Labels
Comments
Ain't pretty, but here's how one library does it: // we must hijack pushState and replaceState because we need to
// detect when consumer attempts to use and trigger a page load
this.historyChangeStates = [window.history.pushState, window.history.replaceState];
this.historyChangeStates.forEach((method) => {
window.history[method.name] = (...args) => {
const [state] = args;
method.apply(history, args);
this.changedUrl(state);
};
}); https://github.com/mkay581/router-component/blob/master/src/router-component.ts#L47 |
I just ran into this too, noticing that when my app updates the route via |
Our router doesn't monitor pushState/replaceState - we only watch link clicks and back/forward. The idea is that if you call those functions, you can also manipulate your state in script (typically calling the same callback you give |
Ok, thank you @keanulee ! |
Probably a little late, but in my code I normally just emit popstate:
As a bonus, I can use the state to pass parameters:
Is this not recommended? |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
If URL changes due to pushState/replaceState, installRouter does not capture it.
The text was updated successfully, but these errors were encountered: