init 初始化

This commit is contained in:
yuping
2023-01-07 02:29:35 +08:00
parent 38ed53736f
commit 0d068739e6
20 changed files with 384 additions and 91 deletions

View File

@@ -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
}

View File

@@ -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