2026-02-13 17:34:32 +08:00
|
|
|
import { createRouter, createWebHistory } from 'vue-router'
|
|
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
history: createWebHistory(import.meta.env.BASE_URL),
|
|
|
|
|
routes: [
|
|
|
|
|
{
|
|
|
|
|
path: '/',
|
|
|
|
|
name: 'home',
|
2026-02-24 09:59:22 +08:00
|
|
|
component: () => import('../views/HomeView.vue'),
|
|
|
|
|
meta: { requiresAuth: false }
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/auth',
|
|
|
|
|
name: 'auth',
|
|
|
|
|
component: () => import('../views/AuthView.vue'),
|
|
|
|
|
meta: { requiresAuth: false, hideNav: true }
|
2026-02-13 17:34:32 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/products',
|
|
|
|
|
name: 'products',
|
2026-02-24 09:59:22 +08:00
|
|
|
component: () => import('../views/ProductListView.vue'),
|
|
|
|
|
meta: { requiresAuth: true }
|
2026-02-13 17:34:32 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/product/:id',
|
|
|
|
|
name: 'product-detail',
|
2026-02-24 09:59:22 +08:00
|
|
|
component: () => import('../views/ProductDetailView.vue'),
|
|
|
|
|
meta: { requiresAuth: true, hideNav: true }
|
2026-02-13 17:34:32 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/cart',
|
|
|
|
|
name: 'cart',
|
2026-02-24 09:59:22 +08:00
|
|
|
component: () => import('../views/CartView.vue'),
|
|
|
|
|
meta: { requiresAuth: true }
|
2026-02-13 17:34:32 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/profile',
|
|
|
|
|
name: 'profile',
|
2026-02-24 09:59:22 +08:00
|
|
|
component: () => import('../views/ProfileView.vue'),
|
|
|
|
|
meta: { requiresAuth: true }
|
2026-02-13 17:34:32 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/wishlist',
|
|
|
|
|
name: 'wishlist',
|
2026-02-24 09:59:22 +08:00
|
|
|
component: () => import('../views/WishlistView.vue'),
|
|
|
|
|
meta: { requiresAuth: true }
|
2026-02-13 17:34:32 +08:00
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
path: '/settings',
|
|
|
|
|
name: 'settings',
|
2026-02-24 09:59:22 +08:00
|
|
|
component: () => import('../views/SettingsView.vue'),
|
|
|
|
|
meta: { requiresAuth: true, hideNav: true }
|
2026-02-13 17:34:32 +08:00
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-24 09:59:22 +08:00
|
|
|
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()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2026-02-13 17:34:32 +08:00
|
|
|
export default router
|