Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

fnlctrl
Copy link
Member

@fnlctrl fnlctrl commented Oct 17, 2016

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.

…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 () {}
Copy link
Member Author

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()
Copy link
Member Author

@fnlctrl fnlctrl Oct 17, 2016

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'

@fnlctrl
Copy link
Member Author

fnlctrl commented Oct 17, 2016

CI bug again... sigh..

@posva
Copy link
Member

posva commented Oct 18, 2016

I don't know yet how to handle that dummy function, but this function is worth some extra tests

@LinusBorg LinusBorg added the 2.x label Oct 19, 2016
@yyx990803
Copy link
Member

yyx990803 commented Nov 13, 2016

merged as 83418bc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants