daqjs
Version:
#### 技术组成
39 lines (36 loc) • 842 B
JavaScript
/*
* @Author: tianshi.hjx
* @Date: 2021-04-15 19:13:07
* @Description: 路由辅助组件
* @Last Modified by: tianshi.hjx
* @Last Modified time: 2021-04-15 19:47:46
*/
import React from 'react';
import { map } from 'lodash';
import { Route } from 'react-router-dom';
/**
* split code page
* @param {*} props
* @returns
*/
const DynamicRoute = ({ page, routes, ...otherProps }) => {
if (!page) {
return null
}
// 动态文件
const AsyncPage = loadable(() => import(`@/pages${page}`))
return (
<Route
{...otherProps}
render={() => <AsyncPage page={page} children={routes && <RoutePatch routes={routes} />} />}
/>
)
}
/**
* 路由
* @param {*} param0
* @returns
*/
export const RoutePatch = ({ routes }) => {
return map(routes, props => <DynamicRoute key={props.path} {...props} />)
}