How to navigate using vue router from Vuex actions

前端 未结 5 472
既然无缘
既然无缘 2020-12-03 06:12

I am creating a web app with Vue 2.x and Vuex 2.x. I am fetching some information from a remote location via an http call, I want that if that call fails I should redirect t

5条回答
  •  被撕碎了的回忆
    2020-12-03 07:12

    This example may help you.

    main.js

    import Vue from "vue";
    import VueRouter from "vue-router";
    
    ...
    
    Vue.use(VueRouter);
    
    export const router = new VueRouter({
        mode: 'hash',
        base: "./",
        routes: [
            { path: "/", component: welcome},
            { path: "/welcome", component: welcome},
    
        ]
    })
    

    actions.js

    import {router} from "../main.js"
    
    export const someAction = ({commit}) => {
    
        router.push("/welcome");
    } 
    

提交回复
热议问题