-
Notifications
You must be signed in to change notification settings - Fork 130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code Splitting #19
Comments
Sure! UI-Router Core 1.0 introduced future states and lets you lazy load them when needed. {
name: 'lazy',
url: '/this-is-lazy',
lazyLoad: () => System.import('./lazyLoadState')
} The import MyComponent from './MyComponent';
const state = {
name: 'lazy',
url: '/this-is-lazy',
component: MyComponent
};
export default { states: [state] } Note that the syntax for lazy loading a JS module depends on the bundler you use. Since the This doesn't prevent you from writing a small helper function to reduce this verbosity: const lazyLoadModule = (moduleName) => new Promise((resolve, reject) => {
require.ensure([], () => { resolve(require(moduleName).default) });
});
const state = {
name: 'lazy',
url: '/this-is-lazy',
lazyLoad: () => lazyLoadModule('./lazyLoadState')
} In any case I wrote a small working example, hope it helps: http://www.webpackbin.com/Ekiu1rHNz Also, you can take a look at the core documentation regarding future states here: https://ui-router.github.io/docs/latest/interfaces/state.statedeclaration.html#lazyload Let me know if you have any doubt |
http://www.webpackbin.com/Ekiu1rHNz link is no longer working I tried the code-splitting with |
I'm thinking the code-splitting's problem is caused by using Here's my router states, app component is loaded via _import:
Here's the components/App:
The chunk loads, Is there a plunker or webpackbin example with code-splitting usage, and also with I have good experience with |
@MichaelBuen and for anyone else who stumbles upon this issue, I fixed this by exporting a
|
Is there a way to use route-based code splitting with ui-router/react?
The text was updated successfully, but these errors were encountered: