Skip to content

Instantly share code, notes, and snippets.

@nightspirit
Created August 29, 2019 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nightspirit/b6d78267855018e09f84e96e608b9221 to your computer and use it in GitHub Desktop.
Save nightspirit/b6d78267855018e09f84e96e608b9221 to your computer and use it in GitHub Desktop.
react-loadable + react-router
import React from 'react'
import { Switch, Route } from 'react-router-dom'
import Loadable from 'react-loadable'
const Loading = () => <div>loading...</div>
const Home = Loadable({
loader: () => import('./Home'),
loading: Loading
})
const Product = Loadable({
loader: () => import('./Product'),
loading: Loading
})
const About = Loadable({
loader: () => import('./About'),
loading: Loading
})
const App = () => (
<Switch>
<Route exact path="/" component={Home}/>
<Route path="/product" component={Product}/>
<Route path="/about" component={About}/>
<Route component={NoMatch}/>
</Switch>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment