验证中...
片段 1 片段 2
asyncComponent.jsx
原始数据 复制代码
import React, { Component } from 'react';
export default function asyncComponent(importComponent) {
class AsyncComponent extends Component {
constructor(props) {
super(props);
this.state = {
component: null
};
}
async componentDidMount() {
const { default: component } = await importComponent();
this.setState({ component });
}
render() {
const C = this.state.component;
return C ? <C {...this.props } /> : null;
}
}
return AsyncComponent;
}
route.js
原始数据 复制代码
import asyncComponent from '../utils/asyncComponent'
const OrderList = asyncComponent(() => import('../view/order/list'))
const OrderDetail = asyncComponent(() => import('../view/order/detail'))
const routes = [
{
path: '/trade/order',
component: OrderList,
breadcrumbName: 'order',
breadcrumbPath: '/trade/order'
},
{
path: '/trade/order/detail',
component: OrderDetail,
breadcrumbName: 'order/detail',
breadcrumbPath: '/trade/order/detail'
}
]
export default routes

评论列表( 0 )

你可以在登录后,发表评论

9_float_left_people 9_float_left_close