mirror of
https://github.com/iczer/vue-antd-admin
synced 2025-04-06 04:00:06 +08:00
chore: resolve warning of duplicate name in async router; 🌟
This commit is contained in:
parent
bceb33996b
commit
c19e3d5a1e
@ -53,7 +53,7 @@ function parseRoutes(routesConfig, routerMap) {
|
|||||||
* @param routesConfig
|
* @param routesConfig
|
||||||
*/
|
*/
|
||||||
function loadRoutes({router, store, i18n}, routesConfig) {
|
function loadRoutes({router, store, i18n}, routesConfig) {
|
||||||
// 如果 routesConfig 有值,则更新到本地localStorage,否则从本地localStorage获取
|
// 如果 routesConfig 有值,则更新到本地,否则从本地获取
|
||||||
if (routesConfig) {
|
if (routesConfig) {
|
||||||
store.commit('account/setRoutesConfig', routesConfig)
|
store.commit('account/setRoutesConfig', routesConfig)
|
||||||
} else {
|
} else {
|
||||||
@ -61,14 +61,32 @@ function loadRoutes({router, store, i18n}, routesConfig) {
|
|||||||
}
|
}
|
||||||
if (routesConfig && routesConfig.length > 0) {
|
if (routesConfig && routesConfig.length > 0) {
|
||||||
const routes = parseRoutes(routesConfig, routerMap)
|
const routes = parseRoutes(routesConfig, routerMap)
|
||||||
router.matcher = new Router(router.options).matcher
|
const finalRoutes = mergeRoutes(router.options.routes, routes)
|
||||||
router.addRoutes(routes)
|
router.options = {...router.options, routes: finalRoutes}
|
||||||
const menuRoutes = routes.find(item => item.path === '/').children
|
router.matcher = new Router({...router.options, routes:[]}).matcher
|
||||||
|
router.addRoutes(finalRoutes)
|
||||||
|
const menuRoutes = finalRoutes.find(item => item.path === '/').children
|
||||||
mergeI18nFromRoutes(i18n, menuRoutes)
|
mergeI18nFromRoutes(i18n, menuRoutes)
|
||||||
store.commit('setting/setMenuData', menuRoutes)
|
store.commit('setting/setMenuData', menuRoutes)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 合并路由
|
||||||
|
* @param target {Route[]}
|
||||||
|
* @param source {Route[]}
|
||||||
|
* @returns {Route[]}
|
||||||
|
*/
|
||||||
|
function mergeRoutes(target, source) {
|
||||||
|
const targetMap = {}
|
||||||
|
const sourceMap = {}
|
||||||
|
target.forEach(item => targetMap[item.path] = item)
|
||||||
|
source.forEach(item => sourceMap[item.path] = item)
|
||||||
|
const routesMap = {...targetMap}
|
||||||
|
Object.keys(sourceMap).forEach(key => routesMap[key] = sourceMap[key])
|
||||||
|
return Object.values(routesMap)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录守卫
|
* 登录守卫
|
||||||
* @param router 应用路由实例
|
* @param router 应用路由实例
|
||||||
|
Loading…
x
Reference in New Issue
Block a user