优化了路由配置
This commit is contained in:
parent
85dcc74e11
commit
b38c6a7d47
@ -5,6 +5,14 @@ import { useUserStore } from '../stores/user'
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
redirect: to => {
|
||||
// 如果已登录,重定向到后台首页,否则重定向到登录页
|
||||
const userStore = useUserStore()
|
||||
return userStore.isLoggedIn ? '/dashboard' : '/login'
|
||||
}
|
||||
},
|
||||
{
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
@ -115,7 +123,7 @@ router.beforeEach((to, from, next) => {
|
||||
if (to.matched.some(record => record.meta.requiresAuth) && !userStore.isLoggedIn) {
|
||||
next({
|
||||
path: '/login',
|
||||
query: { redirect: to.fullPath } // 保存原目标路径
|
||||
query: { redirect: to.fullPath }
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
|
Loading…
x
Reference in New Issue
Block a user