1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| import { createRouter, createWebHistory } from 'vue-router'
const routes = [ { path: '/', component: () => import('@/layouts/ShopLayout.vue'), children: [ { path: '', name: 'Home', component: () => import('@/views/shop/Home.vue'), meta: { title: '首页' } }, { path: 'products', name: 'ProductList', component: () => import('@/views/shop/ProductList.vue'), meta: { title: '商品列表' } }, { path: 'product/:id', name: 'ProductDetail', component: () => import('@/views/shop/ProductDetail.vue'), meta: { title: '商品详情' }, props: true }, { path: 'cart', name: 'Cart', component: () => import('@/views/shop/Cart.vue'), meta: { title: '购物车' } }, { path: 'checkout', name: 'Checkout', component: () => import('@/views/shop/Checkout.vue'), meta: { title: '结算', requiresAuth: true } }, { path: 'user', component: () => import('@/layouts/UserLayout.vue'), meta: { requiresAuth: true }, children: [ { path: 'profile', name: 'UserProfile', component: () => import('@/views/user/Profile.vue'), meta: { title: '个人中心' } }, { path: 'orders', name: 'UserOrders', component: () => import('@/views/user/Orders.vue'), meta: { title: '我的订单' } }, { path: 'order/:orderId', name: 'OrderDetail', component: () => import('@/views/user/OrderDetail.vue'), meta: { title: '订单详情' }, props: true }, { path: 'favorites', name: 'Favorites', component: () => import('@/views/user/Favorites.vue'), meta: { title: '我的收藏' } } ] } ] }, { path: '/login', name: 'Login', component: () => import('@/views/auth/Login.vue'), meta: { title: '登录' } }, { path: '/register', name: 'Register', component: () => import('@/views/auth/Register.vue'), meta: { title: '注册' } }, { path: '/:pathMatch(.*)*', name: 'NotFound', component: () => import('@/views/errors/NotFound.vue'), meta: { title: '页面未找到' } } ]
const router = createRouter({ history: createWebHistory(), routes, scrollBehavior(to, from, savedPosition) { if (savedPosition) { return savedPosition } else if (to.hash) { return { el: to.hash, behavior: 'smooth' } } else { return { top: 0, behavior: 'smooth' } } } })
export default router
|