import HomePage from './pages/home.vue';
import Home2Page from './pages/home2.vue';
import NotFoundPage from './pages/not-found.vue';
export default [
{
path: '/',
component: HomePage,
// check if the user is logged in
beforeEnter: checkAuth,
},
{
path: '/home2',
component: Home2Page,
},
{
path: '(.*)',
component: NotFoundPage
}
];
function checkAuth(to, from, resolve, reject) {
if (true) {
resolve({
component: Home2Page
});
} else {
reject();
}
}
为什么此checkAuth函数不起作用?我尝试检查Page是否需要Auth,何时需要功能checkAuth触发。如果在这种情况下Auth为true,则应加载其他页面。
答案 0 :(得分:0)
您必须使用redirect
属性而不是beforeEnter
。
redirect: function (route, resolve, reject) {
if (true) {
resolve('myUrl');
}
else reject();
}