fix: problem that old routes configuration not clearing when merging async routes; :bug:
修复:合并异步路由时,旧的路由配置未及时清除的问题。
| | |
| | | { |
| | | "name": "vue-antd-admin", |
| | | "version": "0.6.0", |
| | | "version": "0.6.1", |
| | | "homepage": "https://iczer.github.io/vue-antd-admin", |
| | | "private": true, |
| | | "scripts": { |
| | |
| | | import {loadRoutes, loadGuards} from '@/utils/routerUtil' |
| | | import {loadRoutes, loadGuards, setAppOptions} from '@/utils/routerUtil' |
| | | import {loadInterceptors} from '@/utils/request' |
| | | import guards from '@/router/guards' |
| | | import interceptors from '@/utils/axios-interceptors' |
| | |
| | | * @param router 应用的路由实例 |
| | | * @param store 应用的 vuex.store 实例 |
| | | * @param i18n 应用的 vue-i18n 实例 |
| | | * @param i18n 应用的 message 实例 |
| | | */ |
| | | function bootstrap({router, store, i18n, message}) { |
| | | // 设置应用配置 |
| | | setAppOptions({router, store, i18n}) |
| | | // 加载 axios 拦截器 |
| | | loadInterceptors(interceptors, {router, store, i18n, message}) |
| | | // 加载路由 |
| | | loadRoutes({router, store, i18n}) |
| | | loadRoutes() |
| | | // 加载路由守卫 |
| | | loadGuards(guards, {router, store, i18n, message}) |
| | | } |
| | |
| | | // 获取路由配置 |
| | | getRoutesConfig().then(result => { |
| | | const routesConfig = result.data.data |
| | | loadRoutes({router: this.$router, store: this.$store, i18n: this.$i18n}, routesConfig) |
| | | loadRoutes(routesConfig) |
| | | this.$router.push('/dashboard/workplace') |
| | | this.$message.success(loginRes.message, 3) |
| | | }) |
| | |
| | | function filterMenu(menuData, permissions, roles) { |
| | | menuData.forEach(menu => { |
| | | if (menu.meta && menu.meta.invisible === undefined) { |
| | | menu.meta.invisible = !hasAuthority(menu, permissions, roles) |
| | | if (!hasAuthority(menu, permissions, roles)) { |
| | | menu.meta.invisible = true |
| | | } |
| | | if (menu.children && menu.children.length > 0) { |
| | | filterMenu(menu.children, permissions, roles) |
| | | } |
| | |
| | | import {mergeI18nFromRoutes} from '@/utils/i18n' |
| | | import Router from 'vue-router' |
| | | import deepMerge from 'deepmerge' |
| | | import basicOptions from '@/router/async/config.async' |
| | | |
| | | //应用配置 |
| | | let appOptions = { |
| | | router: undefined, |
| | | i18n: undefined, |
| | | store: undefined |
| | | } |
| | | |
| | | /** |
| | | * 设置应用配置 |
| | | * @param options |
| | | */ |
| | | function setAppOptions(options) { |
| | | const {router, store, i18n} = options |
| | | appOptions.router = router |
| | | appOptions.store = store |
| | | appOptions.i18n = i18n |
| | | } |
| | | |
| | | /** |
| | | * 根据 路由配置 和 路由组件注册 解析路由 |
| | |
| | | |
| | | /** |
| | | * 加载路由 |
| | | * @param router 应用路由实例 |
| | | * @param store 应用的 vuex.store 实例 |
| | | * @param i18n 应用的 vue-i18n 实例 |
| | | * @param routesConfig 路由配置 |
| | | * @param routesConfig {RouteConfig[]} 路由配置 |
| | | */ |
| | | function loadRoutes({router, store, i18n}, routesConfig) { |
| | | function loadRoutes(routesConfig) { |
| | | //兼容 0.6.1 以下版本 |
| | | /*************** 兼容 version < v0.6.1 *****************/ |
| | | if (arguments.length > 0) { |
| | | const arg0 = arguments[0] |
| | | if (arg0.router || arg0.i18n || arg0.store) { |
| | | routesConfig = arguments[1] |
| | | console.error('the usage of signature loadRoutes({router, store, i18n}, routesConfig) is out of date, please use the new signature: loadRoutes(routesConfig).') |
| | | console.error('方法签名 loadRoutes({router, store, i18n}, routesConfig) 的用法已过时, 请使用新的方法签名 loadRoutes(routesConfig)。') |
| | | } |
| | | } |
| | | /*************** 兼容 version < v0.6.1 *****************/ |
| | | |
| | | // 应用配置 |
| | | const {router, store, i18n} = appOptions |
| | | |
| | | // 如果 routesConfig 有值,则更新到本地,否则从本地获取 |
| | | if (routesConfig) { |
| | | store.commit('account/setRoutesConfig', routesConfig) |
| | |
| | | if (asyncRoutes) { |
| | | if (routesConfig && routesConfig.length > 0) { |
| | | const routes = parseRoutes(routesConfig, routerMap) |
| | | formatRoutes(routes) |
| | | const finalRoutes = mergeRoutes(router.options.routes, routes) |
| | | const finalRoutes = mergeRoutes(basicOptions.routes, routes) |
| | | formatRoutes(finalRoutes) |
| | | router.options = {...router.options, routes: finalRoutes} |
| | | router.matcher = new Router({...router.options, routes:[]}).matcher |
| | | router.addRoutes(finalRoutes) |
| | |
| | | }) |
| | | } |
| | | |
| | | export {parseRoutes, loadRoutes, formatAuthority, getI18nKey, loadGuards, deepMergeRoutes, formatRoutes} |
| | | export {parseRoutes, loadRoutes, formatAuthority, getI18nKey, loadGuards, deepMergeRoutes, formatRoutes, setAppOptions} |