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 <Com {...this.props}></Com>
}
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'))
}]