Browse Source

路由优化

master
peng.peng 2 years ago
parent
commit
dd5d2b7ef8
  1. 29
      web/client/src/layout/index.js

29
web/client/src/layout/index.js

@ -31,37 +31,38 @@ const Root = props => {
function flat(routes, parentRoute) {
routes.forEach((route, i) => {
let obj = {
const obj = {
path: route.path,
breadcrumb: route.breadcrumb,
component: route.component || null,
authCode: route.authCode || '',
key: route.key
}
if (!route.path.startsWith("/")) {
console.error('路由配置需以 "/" 开始:' + route.path);
key: route.key,
};
if (!route.path.startsWith('/')) {
console.error(`路由配置需以 "/" 开始:${route.path}`);
}
if (route.path.length > 1 && route.path[route.path.length] == '/') {
console.error('除根路由路由配置不可以以 "/" 结束:' + route.path);
console.error(`除根路由路由配置不可以以 "/" 结束:${route.path}`);
}
if (parentRoute && parentRoute != '/') {
obj.path = parentRoute + route.path;
}
if (route.exact) {
obj.exact = true
if (route.exact === false) {
obj.exact = false;
}
if (route.hasOwnProperty('childRoutes')) {
combineRoutes.push(obj);
flat(route.childRoutes, obj.path)
flat(route.childRoutes, obj.path);
} else {
combineRoutes.push(obj)
combineRoutes.push(obj);
}
})
});
}
flat(routes);
return combineRoutes;
}
};
const initReducer = (reducers, reducerName, action) => {
let reducerParams = {}
@ -90,7 +91,7 @@ const Root = props => {
let actions = {
layout: layoutActions
}
for (let s of sections) {
if (!s.key) console.warn('请给你的section添加一个key值,section name:' + s.name);
for (let r of s.routes) {
@ -141,7 +142,7 @@ const Root = props => {
setCombineRoutes(combineRoutes.map(route => (
<Route
key={route.key}
exact={route.hasOwnProperty('exact') ? route.exact : true}
exact={Object.prototype.hasOwnProperty.call(route, 'exact') ? route.exact : true}
path={route.path}
component={route.component}
/>

Loading…
Cancel
Save