封装react 路由懒加载

import React ,{Component} from 'react'
function LoadAsync(asyncComponent){
return class extends Component{
state={
Com:null
}
render(){
let {Com} =this.state
if(Com===null){
return null
}
return
}
async componentDidMount(){
const Com=await asyncComponent();
this.setState({
Com:Com.default
})
}
}
}
export default LoadAsync

调用:
import LoadAsync from 'HOCcomponent/LoadAsync';
const routerConfig = [{
path:"/login",
component:LoadAsync(() => import('../login'))
}]

你可能感兴趣的:(封装react 路由懒加载)