-
-
Notifications
You must be signed in to change notification settings - Fork 5k
history is undefined when the router.replace is called before injecting the router into Vue instance #795
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
Comments
history
is undefined when the router.replace is called before injecting the router into Vue instace
You should do it after injecting the router into a Vue instance. I think this is intended, but would like some input from @fnlctrl and/or @yyx990803 |
That However, if you only need For history mode, it's simply |
@HashemQolami Did it solve your problem? |
@fnlctrl hmm.. that makes sense. I guess you meant the I was under the assumption that |
Yeah.. fixed it.
I was wrong about it, and you probably missed my updated comment above 😂 . |
Does setting up the I am asking as it seems that the |
It's nessessary by the fundamentals of the implemented transitioning process. When you do Also, things like the in-component beforeRouteLeave hook are executed by etc. pp. |
I'm looking into this, looks like basic functionalities like replace/push can really be performed before vue instance initialization, with some changes to the source. |
Not sure the options that could be available exceed what window.history offers, but happy to be proven wrong :) |
@LinusBorg I didn't mean you're wrong, sorry if I made you think that... Your explanation was perfect, and I'm just thinking that it may be an improvement to allow users to do basic replace/push before initializing root vue instance. And I just got a proof-of-concept working that passed all tests, will submit a PR shortly. ;) |
I didn't take it that way, don't worry ;) I hope you're successful |
…795) Previously it would throw errors. Allowed methods: push, replace, go, back, forward Reason: These methods only try to manipulate browser history, and should work even when root vue instance has not been created. Common use case: Call `router.replace()` to set browser url state. This action doesn't require vue's existence, so it shouldn't throw an error when called before vue's instantiation. Otherwise, users may need to check router's actual mode after fallback (history or hash) and then call `history.replaceState` or `location.replace` accordingly.
fixed via 83418bc |
…795) Previously it would throw errors. Allowed methods: push, replace, go, back, forward Reason: These methods only try to manipulate browser history, and should work even when root vue instance has not been created. Common use case: Call `router.replace()` to set browser url state. This action doesn't require vue's existence, so it shouldn't throw an error when called before vue's instantiation. Otherwise, users may need to check router's actual mode after fallback (history or hash) and then call `history.replaceState` or `location.replace` accordingly.
I need to call
router.replace
before injecting therouter
into theVue
instance. But can't figure out whyhistory
property is undefined in that situation:Here is the online example (check the console) and the code snippet:
The text was updated successfully, but these errors were encountered: