vuejs / vuex-router-sync

Effortlessly keep vue-router and vuex store in sync.
MIT License
2.52k stars 125 forks source link

Documentation on how it syncs within existing lifecycle #81

Closed robokozo closed 6 years ago

robokozo commented 6 years ago

I'd like to see documentation on where this 'plugin' fits into the existing navigation lifecycle seen here: https://router.vuejs.org/en/advanced/navigation-guards.html

The one trap I keep falling into is that I cannot reliably figure out when the module is being updated.

So in my component I have to keep doing things like this:

    beforeRouteUpdate(to, from, next){
        this.$store.dispatch('selectedPost/loadSelectedPostAsync', to.params.postId)
        next()
    },

While I 'feel' like I should already have access to the up-to-date postId directly from the route module... it doesn't get updated until later. I don't know when that is.

robokozo commented 6 years ago

Could it maybe hook into .beforeResolve?

LinusBorg commented 6 years ago

It uses afterEach, which makes sense because in all other hooka, the navigation has not yet been confirmed and could be canceled or redirected anytime.

The source is barely 80 lines, just take a look

https://github.com/vuejs/vuex-router-sync/blob/master/src/index.js#L35