react-router-async-component
Async route component for React-router
npm i -D react-router-async-component
react-router-async-component provides <Acomponent>
tag to load your components lazily.
Usage Example
const Page = { const page = propsmatchparamswildcard || 'index' return <Acomponent from= import`page/` notFound= import`page/notfound` onError= /* new */ import`page/error` />} const Main = <HashRouter> <div> <ul> <li><Link to="/">Home</Link></li> <li><Link to="/clock">Clock</Link></li> </ul> <hr/> <Route exact path="/" component= <Acomponent from=import'page/home'/> /> <Route path="/clock" component= <Acomponent from=import'page/clock' name="AliasName"/> /> <Route path="/:wildcard?" component=Page/> </div> </HashRouter> ;
home.jsx
{ return <div>Home</div> }// props.name === default
clock.jsx
{ return <div>Clock</div> }// props.name === AliasName