feat: base 跳转前check
This commit is contained in:
parent
ac5ca4ba81
commit
0658c9e5fb
|
|
@ -1,5 +1,6 @@
|
||||||
import { createRouter, createWebHistory} from 'vue-router';
|
import { createRouter, createWebHistory} from 'vue-router';
|
||||||
import { authToken } from '@/store/index.js'
|
import { authToken } from '@/store/index.js'
|
||||||
|
import http from "@/api/request.js";
|
||||||
const routes = [
|
const routes = [
|
||||||
{ path: "/", redirect: "/login" },
|
{ path: "/", redirect: "/login" },
|
||||||
{
|
{
|
||||||
|
|
@ -54,7 +55,7 @@ const router = createRouter({
|
||||||
routes,
|
routes,
|
||||||
});
|
});
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
if (to.path === "/login") {
|
if (to.path === "/login") {
|
||||||
if (authToken.access) {
|
if (authToken.access) {
|
||||||
next("/home");
|
next("/home");
|
||||||
|
|
@ -63,7 +64,14 @@ router.beforeEach((to, from, next) => {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (authToken.access) {
|
if (authToken.access) {
|
||||||
next();
|
try{
|
||||||
|
await http.get("/check_token/")
|
||||||
|
next();
|
||||||
|
} catch(e){
|
||||||
|
authToken.access = null;
|
||||||
|
authToken.refresh = null;
|
||||||
|
next("/login");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
next("/login");
|
next("/login");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue