Reputation: 1697
Joined a new team, and found below snippet:
const bookListContainer = (location, cb) => {
require.ensure([], require => {
cb(null, require('somepath').default)
}, 'bookList')
}
<Route path="/" component={App}>
<Route path="home" component={HomeComponent} />
<Route path="bookList/:bookId" getComponent={bookListContainer} />
</Route>
what is the difference between component
and getComponent
? And for bookListContainer
, what does it exact do? cannot understand require.ensure()
thanks
Upvotes: 0
Views: 76
Reputation: 10273
This is a way to asynchronously load routes by splitting them into separate bundles.
getComponent
will fire when the route is matched and consequently require what is necessary for that bundle bookList
This is a way to assist reducing the initial load time of your application.
Upvotes: 1
Reputation: 2128
I recommend you to read code splitting: https://webpack.github.io/docs/code-splitting.html
You will learn some important concepts there to understand this code.
Regards!
Upvotes: 2