Files
FiDA_Front/src/router/index.ts
2026-02-04 10:01:50 +08:00

54 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { createRouter, createWebHistory } from 'vue-router'
/**
* 路由缓存机制:
* 1. 设置路由的meta属性为{ cache: true },表示需要缓存
* 2. App.vue中使用RouteCache组件通过路由的name来进行匹配
* 3. 路由的name默认是文件名,如果文件名与name不一致,通过defineOptions({ name: 'componentName' })来设置
*/
const router = createRouter({
history: createWebHistory('/'),
// history: createWebHistory(import.meta.env.VITE_APP_URL),
routes: [
{
path: '/',
redirect: '/index'
},
{
path: '/index',
name: 'index',
component: () => import('../views/login/index.vue'),
},
{
path: '/login',
name: 'login',
component: () => import('../views/login/login.vue'),
},
{
path: '/register',
name: 'register',
component: () => import('../views/login/register.vue'),
},
{
path: '/home',
name: 'home',
component: () => import('../views/home/index.vue'),
children: [
{
path: 'test',
name: 'test',
component: () => import('../views/home/test.vue'),
meta: { topNavStyle: '2' }
}
]
},
{
path: '/:pathMatch(.*)',
name: '404',
component: () => import('../views/404.vue'),
}
]
})
export default router