mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/student-h5.git
synced 2025-12-09 19:06:47 +08:00
init 初始化
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
const routes = [];
|
||||
const context =import.meta.glob("../views/*/*.vue")
|
||||
const context =import.meta.glob("../views/*/*.vue", {eager: true})
|
||||
Object.keys(context).forEach(path => {
|
||||
const componentName = path.replace(/.*\/([^\\.\\/]*)\.vue$/, '$1');
|
||||
routes.push({
|
||||
path: `/${componentName.toLowerCase()}`,
|
||||
name: componentName,
|
||||
component: () => import(path/* @vite-ignore */),
|
||||
component: context[path].default,
|
||||
meta: {
|
||||
isLink: true
|
||||
}
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
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
|
||||
{
|
||||
path: '/',
|
||||
name: '首页',
|
||||
redirect: routesConfig[0].path
|
||||
},
|
||||
...routesConfig
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory('/student-h5'),
|
||||
routes
|
||||
history: createWebHistory(import.meta.env.VITE_BASE),
|
||||
routes
|
||||
})
|
||||
router.beforeEach((to, from, next) => {
|
||||
if (!getCookie('token')) {
|
||||
to.path === '/login' ? next() : next({path: '/login', query: {returnUrl: to.fullPath}})
|
||||
return
|
||||
}
|
||||
next()
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user