Framework7路由保护

时间:2018-09-05 13:24:13

标签: vue.js html-framework-7

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,则应加载其他页面。

1 个答案:

答案 0 :(得分:0)

您必须使用redirect属性而不是beforeEnter

示例(retrieved from the docs):

redirect: function (route, resolve, reject) {
  if (true) {
    resolve('myUrl');
  }
  else reject();
}