研发图纸文件管理系统-前端项目
chenghongxing
2020-09-03 4856f06f41563b8fa2d12aaa1247d8925eb43aa3
fix: configuration problem of first route's path; :bug:
修复:一级路由 path 配置问题;
2个文件已修改
22 ■■■■ 已修改文件
src/router/index.js 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/routerUtil.js 18 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router/index.js
@@ -1,6 +1,6 @@
import Vue from 'vue'
import Router from 'vue-router'
import {formatAuthority} from '@/utils/routerUtil'
import {formatRoutes} from '@/utils/routerUtil'
Vue.use(Router)
@@ -25,7 +25,7 @@
 */
function initRouter(isAsync) {
  const options = isAsync ? require('./async/config.async').default : require('./config').default
  formatAuthority(options.routes)
  formatRoutes(options.routes)
  return new Router(options)
}
export {loginIgnore, initRouter}
src/utils/routerUtil.js
@@ -66,7 +66,7 @@
  if (asyncRoutes) {
    if (routesConfig && routesConfig.length > 0) {
      const routes = parseRoutes(routesConfig, routerMap)
      formatAuthority(routes)
      formatRoutes(routes)
      const finalRoutes = mergeRoutes(router.options.routes, routes)
      router.options = {...router.options, routes: finalRoutes}
      router.matcher = new Router({...router.options, routes:[]}).matcher
@@ -132,6 +132,20 @@
    })
  }
  return parseRoutesMap(merge)
}
/**
 * 格式化路由
 * @param routes 路由配置
 */
function formatRoutes(routes) {
  routes.forEach(route => {
    const {path} = route
    if (!path.startsWith('/') && path !== '*') {
      route.path = '/' + path
    }
  })
  formatAuthority(routes)
}
/**
@@ -203,4 +217,4 @@
  })
}
export {parseRoutes, loadRoutes, formatAuthority, getI18nKey, loadGuards, deepMergeRoutes}
export {parseRoutes, loadRoutes, formatAuthority, getI18nKey, loadGuards, deepMergeRoutes, formatRoutes}