Giter Club home page Giter Club logo

react-router-dispatcher-chunk's Introduction

react-router-dispatcher-chunk

npm npm CircleCI branch Test Coverage Maintainability Conventional Commits

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
import React from 'react';
import { chunk } from 'react-chunk';

// Dynamically imported route component
const AboutRouteChunk = chunk(() => import('./aboutRoute'))();

export default AboutRouteChunk

Define the application routes using react-router-config.

// routes.js
import Root from './rootRoute';
import AboutRouteChunk = from './aboutRouteChunk';
import {routeChunk} from 'react-router-dispatcher-chunk';

// react-router-config routes
const routes = [
  { component: Root,
    routes: [
      { path: '/',
        exact: true,
        component: Home
      },
      {
        // the client will pre-load the about chunk BEFORE rendering the route
        path: '/about',
        component: routeChunk()(AboutRouteChunk)
      }
    ]
  }
]

Configuring the dispatcher action using react-router-dispatcher.

IMPORTANT: if using CHUNK, it must be the first configured route action.

import { createRouteDispatchers } from 'react-router-dispatcher';
import { CHUNK } from 'react-router-dispatcher-chunk';
import routes from './routes';

const {
    UniversalRouteDispatcher,
    ClientRouteDispatcher,
    dispatchClientActions,
    dispatchServerActions
} = createRouteDispatchers(routes, [CHUNK]);

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

react-router-dispatcher-chunk's People

Contributors

adam-26 avatar

Watchers

 avatar Heaven avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.