mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/student-h5.git
synced 2025-12-10 03:16:46 +08:00
30 lines
885 B
JavaScript
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 |