import { createRouter, createWebHistory } from 'vue-router' /** * 路由缓存机制: * 1. 设置路由的meta属性为{ cache: true },表示需要缓存 * 2. App.vue中使用RouteCache组件,通过路由的name来进行匹配 * 3. 路由的name默认是文件名,如果文件名与name不一致,通过defineOptions({ name: 'componentName' })来设置 */ const router = createRouter({ routes: [ { path: '/', name: 'home', component: () => import('../views/home/index.vue') }, { path: '/collectionStory', name: 'collectionStory', component: () => import('../views/collectionStory/index.vue') }, { path: '/brand', name: 'brand', component: () => import('../views/brand/index.vue') }, { path: '/brand/:id', name: 'brandDetail', component: () => import('../views/brandDetail/index.vue') }, { path: '/digitalItem', name: 'digitalItem', component: () => import('../views/digitalItem/index.vue'), meta: { cache: true } }, { path: '/digitalItem/:id', name: 'digitalItemDetail', component: () => import('../views/digitalDetail/index.vue') }, { path: '/settings', name: 'settings', component: () => import('@/views/setting/index.vue'), meta: { cache: true } }, { path: '/shoppingCart', // 购物车 name: 'shoppingCart', component: () => import('@/views/shoppingCart/index.vue') }, { path: '/notifications', name: 'notifications', component: () => import('@/views/notifications/index.vue') }, { path: '/wardrobe', name: 'wardrobe', component: () => import('@/views/wardrobe/index.vue') }, { path:'/account', name:'account', component:()=>import('@/views/account/index.vue') }, { path: '/:pathMatch(.*)', name: '404', component: () => import('../views/404.vue') } ], history: createWebHistory('/') }) router.beforeEach((to, from, next) => { next() }) router.afterEach(() => {}) export default router