diff --git a/src/axios.js b/src/axios.js index f103469..d28b1ca 100644 --- a/src/axios.js +++ b/src/axios.js @@ -1,5 +1,6 @@ import axios from 'axios' import router from '@/router' +import store from '@/store/store' const domain = "" // import themeConfig from '@/../themeConfig.js' @@ -8,6 +9,7 @@ const noAthUrl =["/register/form", "/auth/register", "/pages/error-404", "/pages/error-403", + "/register/form", "/auth/forgot-password"] const token = sessionStorage.getItem("accessToken") || sessionStorage.accessToken || null const headers = { @@ -26,8 +28,8 @@ myax.interceptors.request.use( function (config) { // Do something before request is sent if (process.browser) { - if (!sessionStorage.getItem("accessToken") && !noAthUrl.includes(router.currentRoute.fullPath)) { - console.log("router req::::",router.currentRoute) + if (!sessionStorage.getItem("accessToken") && !noAthUrl.includes(store.state.route.route)) { + console.log("router req::::",store.state.route.route) router.push('/auth/login'); } } @@ -64,11 +66,11 @@ myax.interceptors.response.use( return res; }, function ({response}) { - if (response.status === 401 && !noAthUrl.includes(router.currentRoute.fullPath)) { - console.log("router response::::",router.currentRoute) + if (response.status === 401 && !noAthUrl.includes(store.state.route.route)) { + console.log("router response::::",store.state.route.route) router.push({path:'/auth/login'}); } - if(response.status === 403 && router.currentRoute.fullPath !== '/error-403'){ + if(response.status === 403 && store.state.route.route !== '/error-403'){ console.log('403333333333333') router.push({path:'/error-403'}); } diff --git a/src/router.js b/src/router.js index cd74431..589a1eb 100644 --- a/src/router.js +++ b/src/router.js @@ -1,6 +1,7 @@ import Vue from 'vue' import Router from 'vue-router' import 'firebase/auth' +import store from "./store/store"; Vue.use(Router) @@ -151,16 +152,17 @@ const router = new Router({ ], }) -router.afterEach(() => { +router.afterEach((to) => { const appLoading = document.getElementById('loading-bg') if (appLoading) { appLoading.style.display = "none"; } }) -router.beforeEach((to, from, next) => { +router.beforeEach(async (to, from, next) => { // return next(); let isLogin = sessionStorage.getItem('accessToken'); + await store.commit('route/SET_ROUTE',to.path) //console.log("to.path ==> ", to.path); if ( to.path === "/register/form" || diff --git a/src/store/route.js b/src/store/route.js new file mode 100644 index 0000000..980dcbf --- /dev/null +++ b/src/store/route.js @@ -0,0 +1,14 @@ +const state = { + route: '/register/form', +} +const mutations = { + SET_ROUTE(state, route) { + state.route = route + } +} + +export default { + namespaced: true, + state, + mutations, +} diff --git a/src/store/store.js b/src/store/store.js index 937a8f7..15cbc2c 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -43,6 +43,7 @@ import badadv from './badadv/badadv' import points from './point/points' import transaction from './transaction/transaction' import price from './price/price' +import route from './route' export default new Vuex.Store({ getters, @@ -70,7 +71,8 @@ export default new Vuex.Store({ transaction:transaction, price:price, variantAdd:variantAdd, - advModel:advModel + advModel:advModel, + route:route, }, strict: process.env.NODE_ENV !== 'production' })