Files
student-h5/src/router/index.js
2023-01-16 14:40:02 +08:00

30 lines
885 B
JavaScript

import {createRouter, createWebHashHistory, createWebHistory} from 'vue-router';
import routesConfig from './config';
import {getCookie} from "@/api/utils";
// console.log('routesConfig', routesConfig)
const routes = [
{
path: '/',
name: '首页',
redirect: routesConfig[0].path
},
...routesConfig
]
const router = createRouter({
history: createWebHistory(import.meta.env.VITE_BASE),
routes
})
router.beforeEach((to, from, next) => {
if (!getCookie('token')) {
if (import.meta.env.MODE === "development" || import.meta.env.MODE === "test") {
to.path.includes('/login') ? next() : next({path: '/login', query: {returnUrl: to.fullPath}})
}else {
window.location.href = import.meta.env.VITE_BASE_LOGIN_URL + import.meta.env.VITE_BASE+to.fullPath
}
}
next()
})
export default router