router.push in vuex actions
-
Re: Redirect to page after action
Maybe not a hot topic but I saw the question here in the forum how to use this.$router.push in vuex.My solution is quite simple:
- I create an action
export function routeToLogin () { this.$router.push({ path: '/login' }) }
- Then I dispatch this action from any other action I like:
export function logOut (context) { Vue.prototype.$axios.get(process.env.API + 'xxxx/' ...) .then(response => { ... context.dispatch('routeToLogin') })... }
-
@stukki - This might be better in the “Useful Tips” forum.
Scott
-
@s-molinari Of course you’re right, sorry. I just replied to that post, at least I thought to.
-
@stukki Amazing!! I was stuck and now I am not. Thank you for sharing. This ought to be the number 1 question