fix: configuration problem of first route's path; 🐛

修复:一级路由 path 配置问题;
master
chenghongxing 4 years ago
parent 8102c8a924
commit 4856f06f41
  1. 4
      src/router/index.js
  2. 18
      src/utils/routerUtil.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 @@ const loginIgnore = {
*/
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}

@ -66,7 +66,7 @@ function loadRoutes({router, store, i18n}, routesConfig) {
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
@ -134,6 +134,20 @@ function deepMergeRoutes(target, source) {
return parseRoutesMap(merge)
}
/**
* 格式化路由
* @param routes 路由配置
*/
function formatRoutes(routes) {
routes.forEach(route => {
const {path} = route
if (!path.startsWith('/') && path !== '*') {
route.path = '/' + path
}
})
formatAuthority(routes)
}
/**
* 格式化路由的权限配置
* @param routes 路由
@ -203,4 +217,4 @@ function loadGuards(guards, options) {
})
}
export {parseRoutes, loadRoutes, formatAuthority, getI18nKey, loadGuards, deepMergeRoutes}
export {parseRoutes, loadRoutes, formatAuthority, getI18nKey, loadGuards, deepMergeRoutes, formatRoutes}

Loading…
Cancel
Save