React 异步组件

447 阅读1分钟

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

const Index = lazy(() => import('components/Index')); const List = lazy(() => import('components/List'));

class App extends React.Component { render() { return

<Route path="/index" exact component={props => <Index {...props}/>}/> <Route path="/list" exact component={props => <List {...props}/>}/>
} }

function Loading() { return

Loading...

}

export default App;