react按需加载配置

今天就抽时间看了下
react 按需加载配置

import React,{lazy, Suspense} from 'react'
import ReactDom from 'react-dom'
import { HashRouter,  Route, Switch } from 'react-router-dom'

const Room = lazy(() => import("./pages/room"));
const Play = lazy(() => import("./pages/replay"));

function WaitingComponent(Component) {
  return props => (
    <Suspense fallback={<div>Loading...</div>}>
      <Component {...props} />
    </Suspense>
  );
}

ReactDom.render((
  <HashRouter>
    <Switch>
      <Route exact path="/" component={Index} />>
      <Route exact path="/room/:roomid/:userid" component={WaitingComponent(Room)} />
      <Route exact path="/replay/:roomid/:roomToken" component={WaitingComponent(Play)} />
      <Route component={Error} />
    </Switch>
  </HashRouter>
), document.getElementById("app-root"));
文章来源: react按需加载配置