未登录的时候页面跳转问题修复
This commit is contained in:
@@ -7,7 +7,7 @@ const router = createRouter({
|
|||||||
path: '/',
|
path: '/',
|
||||||
name: 'home',
|
name: 'home',
|
||||||
component: () => import('../views/HomeView.vue'),
|
component: () => import('../views/HomeView.vue'),
|
||||||
meta: { requiresAuth: false }
|
meta: { requiresAuth: true }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/auth',
|
path: '/auth',
|
||||||
@@ -62,6 +62,8 @@ router.beforeEach((to, _from, next) => {
|
|||||||
next('/auth')
|
next('/auth')
|
||||||
} else if (to.path === '/auth' && token) {
|
} else if (to.path === '/auth' && token) {
|
||||||
next('/')
|
next('/')
|
||||||
|
} else if (to.path === '/' && !token) {
|
||||||
|
next('/auth')
|
||||||
} else {
|
} else {
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ const fetchShops = async () => {
|
|||||||
shops.value = response.data || []
|
shops.value = response.data || []
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取店铺列表失败:', error)
|
console.error('获取店铺列表失败:', error)
|
||||||
message.error('获取店铺列表失败')
|
message.error('未登录,请先登录')
|
||||||
} finally {
|
} finally {
|
||||||
loadingShops.value = false
|
loadingShops.value = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ const fetchProductDetail = async () => {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取商品详情失败:', error)
|
console.error('获取商品详情失败:', error)
|
||||||
ElMessage.error('获取商品详情失败,请稍后重试')
|
ElMessage.error('未登录,请先登录')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ const fetchProducts = async () => {
|
|||||||
hasMore.value = false
|
hasMore.value = false
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取商品失败:', error)
|
console.error('获取商品失败:', error)
|
||||||
message.error('获取商品失败,请稍后重试')
|
message.error('未登录,请先登录')
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user