如果路径是“/”或“/login”,如何重定向。我正在考虑添加另一个带有“/”的对象,并且组件仍然可以登录,但我不知道这是否是正确的方法。 这是我的路由器。
const router = new Router({
mode: 'history',
linkExactActiveClass: 'active',
routes: [
{
name: 'dashboard',
path: '/dashboard',
component: Dashboard,
meta: {
requiresAuth: true
}
},
{
name: 'profile',
path: '/profile',
component: Profile,
meta: {
requiresAuth: true
}
},
{
name: 'login',
path: '/login',
component: Login,
meta: {
requiresVisitor: true
}
},
{
name: 'logout',
path: '/logout',
component: Logout,
meta: {
requiresAuth: true
}
}
]
});
最佳答案
如果您想使用“/”或“/login”进行重定向,可以尝试这个
const router = new Router({
mode: 'history',
linkExactActiveClass: 'active',
routes: [
{
path: '',
redirectTo: '/login',
pathMatch: 'full'
},
{
name: 'dashboard',
path: '/dashboard',
component: Dashboard,
meta: {
requiresAuth: true
}
},
{
name: 'profile',
path: '/profile',
component: Profile,
meta: {
requiresAuth: true
}
},
{
name: 'login',
path: '/login',
component: Login,
meta: {
requiresVisitor: true
}
},
{
name: 'logout',
path: '/logout',
component: Logout,
meta: {
requiresAuth: true
}
}
]
});
关于vue.js - 如果路径为 '/' 或 '/login' ,如何重定向登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58369954/