Accessing Vuex state when defining Vue-Router routes

后端 未结 6 1942
野的像风
野的像风 2020-11-27 15:53

I have the following Vuex store (main.js):

import Vue from \'vue\'
import Vuex from \'vuex\'

Vue.use(Vuex)

//init sto         


        
6条回答
  •  一向
    一向 (楼主)
    2020-11-27 16:01

    This is how i would to it.

    In App.vue, I will keep a watcher on cookie that stores authentication details. ( Obviously I would store a token containing authentication details as cookie after authentication )

    Now whenever this cookie becomes empty, I will route the user to /login page. Logging out deletes the cookie. Now if user hit back after logging out, now since the cookie doesnot exist, ( which requires user to be logged in ), user will be routed to login page.

提交回复
热议问题