// 先下载react-loadable
npm i react-loadable -S
// 建立一个loadable.js,放在src/until/loadable.js
//引入插件,并导出
import Loadable from 'react-loadable';
export default function withLoadable(comp) {
return Loadable({
//懒加载组件页面
loader: comp,
loading: () => null,
delay: "",
})
}
// 在路由页面统一配置, /router/index 页面引入
import {
HashRouter as Router, Route, Switch, Redirect } from 'react-router-dom'; ---引入路由
import loadable from '../until/loadable' ---引入懒加载
import Home from '../views/Home'; ---非懒加