Commit e9234cbd by 胡锦波

1. init 添加兼容以前的代码

parent b0271a7b
import { RouteConfig } from 'vue-router';
import { Direction } from './direction';
interface RedirectPath {
path: string,
redirect: string,
}
const compatibleUrl = [
{
oldPath: "/SelectOrg",
direction: Direction.Home
},
{
oldPath: "/workadmin/addressbook/home",
direction: Direction.AddressBook
},
{
oldPath: "/workadmin/applicationrecord",
direction: Direction.ApplicationRecord
},
{
oldPath: "/workadmin/OrgManage/Invoicetitles",
direction: Direction.InvoiceTitles
},
{
oldPath: "/workadmin/OrgManage/OrgInfo",
direction: Direction.EnterpriseInfo
},
{
oldPath: "/workadmin/workadmin/OrgManage/ApplySetting",
direction: Direction.ApplicationSetting
},
{
oldPath: "/workadmin/workadmin/OrgManage/AuthorityManage",
direction: Direction.ManagerSetting
},
{
oldPath: "/workadmin/workadmin/OrgManage/Logs",
direction: Direction.ManagerLog
},
];
const direction4AbsolutePathMap = new Map<Direction, string>();
/**
* 根据path 和 direction拿到需要重定向的路径, 主要是适配之前的路由
*/
const setDirectionEnum4Url = function(routes: RouteConfig[], prefix = '') {
for (let i = 0; i < routes.length; i++) {
const route = routes[i];
if (route.meta && route.meta.direction) {
const direction = route.meta.direction;
const curPath = `${prefix}/${route.path}`;
direction4AbsolutePathMap.set(direction, curPath.replace('//', '/'));
continue;
}
if (route.children) {
const curPath = `${prefix}/${route.path}`;
setDirectionEnum4Url(route.children, curPath.replace('//', '/'));
}
}
};
const setCompatibleUrl = function(routes: RouteConfig[]): RedirectPath[] {
setDirectionEnum4Url(routes);
return compatibleUrl.map(i => {
return {
path: i.oldPath,
redirect: direction4AbsolutePathMap.get(i.direction)
} as RedirectPath;
}) || [];
};
export { setCompatibleUrl };
......@@ -2,6 +2,7 @@ import Vue from 'vue';
import VueRouter, { RouteConfig } from 'vue-router';
import { Direction } from './direction';
import { MetaHeader } from './meta-header';
import { setCompatibleUrl } from './compatible-url';
Vue.use(VueRouter);
......@@ -64,6 +65,9 @@ const routes: Array<RouteConfig> = [
}
];
const redirectPath = setCompatibleUrl(routes);
routes.unshift(...redirectPath);
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment