标签功能初版实现
This commit is contained in:
@@ -6,39 +6,65 @@ const router = createRouter({
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: () => import('../views/HomeView.vue')
|
||||
component: () => import('../views/HomeView.vue'),
|
||||
meta: { requiresAuth: false }
|
||||
},
|
||||
{
|
||||
path: '/auth',
|
||||
name: 'auth',
|
||||
component: () => import('../views/AuthView.vue'),
|
||||
meta: { requiresAuth: false, hideNav: true }
|
||||
},
|
||||
{
|
||||
path: '/products',
|
||||
name: 'products',
|
||||
component: () => import('../views/ProductListView.vue')
|
||||
component: () => import('../views/ProductListView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/product/:id',
|
||||
name: 'product-detail',
|
||||
component: () => import('../views/ProductDetailView.vue')
|
||||
component: () => import('../views/ProductDetailView.vue'),
|
||||
meta: { requiresAuth: true, hideNav: true }
|
||||
},
|
||||
{
|
||||
path: '/cart',
|
||||
name: 'cart',
|
||||
component: () => import('../views/CartView.vue')
|
||||
component: () => import('../views/CartView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/profile',
|
||||
name: 'profile',
|
||||
component: () => import('../views/ProfileView.vue')
|
||||
component: () => import('../views/ProfileView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/wishlist',
|
||||
name: 'wishlist',
|
||||
component: () => import('../views/WishlistView.vue')
|
||||
component: () => import('../views/WishlistView.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
},
|
||||
{
|
||||
path: '/settings',
|
||||
name: 'settings',
|
||||
component: () => import('../views/SettingsView.vue')
|
||||
component: () => import('../views/SettingsView.vue'),
|
||||
meta: { requiresAuth: true, hideNav: true }
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
router.beforeEach((to, _from, next) => {
|
||||
const token = localStorage.getItem('accessToken')
|
||||
const requiresAuth = to.meta.requiresAuth as boolean
|
||||
|
||||
if (requiresAuth && !token) {
|
||||
next('/auth')
|
||||
} else if (to.path === '/auth' && token) {
|
||||
next('/')
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user