-
Notifications
You must be signed in to change notification settings - Fork 64
Open
Description
Say with have several modules, one for each page. Each of them is pretty heavy, and its not an option to load them all in advance to prepare static routes map as demonstrated in example (const routes = [{ path: '/foo', component: Page1 },...];
)
Each module contains async-connected page component + appropriate reducer.
first create lazy wrappers for each page:
const Page1 = lazy(async () => {
const moduleBundle = await import(/* webpackChunkName: "Page1" */'src/pages/Page1');
injectAsyncReducer(store, moduleBundle.constants.NAME, moduleBundle.reducer);
return moduleBundle;
});
const Page2 = lazy(async () => {
const moduleBundle = await import(/* webpackChunkName: "Page2" */'src/pages/Page3');
injectAsyncReducer(store, moduleBundle.constants.NAME, moduleBundle.reducer);
return moduleBundle;
});
injectAsyncReducer
function re-configures store and injects reducer for certain page using replaceReducer redux utility.
now init provider, router, suspense-wrapper, define routes and mount tree:
ReactDOM.render(
<Provider store={store}>
<BrowserRouter>
<GenericContainer>
<App>
<Suspense fallback={<div>Loading...</div>}>
<Switch>
<Route path="/page1">
<Page1 />
</Route>
<Route path="/page2">
<Page2 />
</Route>
</Switch>
</Suspense>
</App>
</GenericContainer>
</BrowserRouter>
</Provider>,
renderTarget,
);
so the question, where is the place for <ReduxAsyncConnect>
component here?
Metadata
Metadata
Assignees
Labels
No labels