-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Allow calling instance methods before vue instantiation. (fix #795) #797
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
Conversation
…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.
* inside a `switch case`... | ||
* Advices on how to remove this method are much appreciated. | ||
*/ | ||
onHashChange () {} |
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.
^ help needed.
this.history = new HashHistory(this, options.base, fallback) | ||
this.history.transitionTo(getHash(), () => { | ||
window.addEventListener('hashchange', () => { | ||
this.history.onHashChange() |
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.
This is what made flow unhappy..
Error log (when you remove the dummy method in the comment above):
src/index.js:75
75: this.history.onHashChange()
^^^^^^^^^^^^ property `onHashChange`. Property not found in
75: this.history.onHashChange()
^^^^^^^^^^^^ AbstractHistory
src/index.js:75
75: this.history.onHashChange()
^^^^^^^^^^^^ property `onHashChange`. Property not found in
75: this.history.onHashChange()
^^^^^^^^^^^^ HTML5History
Even when this.history
is guaranteed to have onHashChange
inside case 'hash'
CI bug again... sigh.. |
I don't know yet how to handle that dummy function, but this function is worth some extra tests |
merged as 83418bc |
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
orlocation.replace
accordingly.