index.js 818 Bytes
Newer Older
wb-ct393452's avatar
wb-ct393452 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
import syncConfig from './config';
import asyncConfig from './async/config.async';
import { formatRoutes } from '../utils/routerUtil';

// 不需要登录拦截的路由配置
const loginIgnore = {
  names: ['404', '403'],      //根据路由名称匹配
  paths: ['/login'],   //根据路由fullPath匹配
  /**
   * 判断路由是否包含在该配置中
   * @param route vue-router 的 route 对象
   * @returns {boolean}
   */
  includes(route) {
    return this.names.includes(route.name) || this.paths.includes(route.path)
  }
};

/**
 * 初始化路由实例
 * @param isAsync 是否异步路由模式
 * @returns {options.routes}
 */
function initRouter(isAsync) {
  const options = isAsync ? asyncConfig : syncConfig;
  formatRoutes(options.routes);
  return options;
}


export {loginIgnore , initRouter}