react-router-dispatcher-chunk
Pre-loads react-chunk dynamic route imports for client rendering.
This makes it easy to:
- configure code splitting for routes
- use dynamically loaded route components with static methods
Usage
This package is intended to be used with react-router-config and react-router-dispatcher.
// aboutRouteChunk.js;; // Dynamically imported route componentconst AboutRouteChunk = ;
Define the application routes using react-router-config.
// routes.js;;; // react-router-config routesconst routes = component: Root routes: path: '/' exact: true component: Home // the client will pre-load the about chunk BEFORE rendering the route path: '/about' component: AboutRouteChunk
Configuring the dispatcher action using react-router-dispatcher.
IMPORTANT: if using CHUNK
, it must be the first configured route action.
;;; const UniversalRouteDispatcher ClientRouteDispatcher dispatchClientActions dispatchServerActions } = ;
Install
react-chunk is a peer dependency and must also be installed.
NPM
npm install --save react-chunk react-router-dispatcher-chunk
Yarn
yarn add react-chunk react-router-dispatcher-chunk
API
routeChunk(options)
Options
getChunkLoaderStaticMethodName?: string
: Optional
- Optional, the static method name used to retrieve the chunk loader from the route component(s)
Contribute
For questions or issues, please open an issue, and you're welcome to submit a PR for bug fixes and feature requests.
Before submitting a PR, ensure you run npm test
to verify that your coe adheres to the configured lint rules and passes all tests. Be sure to include unit tests for any code changes or additions.
License
MIT