I assume vuex-router-sync will not help here, since you need a router instance.
Therefore, although this does not seem ideal, you can set the instance as global in the web package, i.e.
global.router = new VueRouter({ routes }) const app = new Vue({ router ...
Now you can: router.push({ name: 'home', params: { id: 1234 }}) from anywhere in your application
Alternatively, if you do not like the idea of ββthe above, you can return the promise from your action. Then, if the action completed successfully, I assume that it causes a mutation or something like that, and you can resolve Promise. However, if it fails and whichever condition requires redirection, you promise to reject .
This way you can redirect routers to a component that just catches the rejected promise and starts the push router, i.e.
# vuex actions: { foo: ({ commit }, payload) => new Promise((resolve, reject) => { if (payload.title) { commit('updateTitle', payload.title) resolve() } else { reject() } })
Guyc
source share