Skip to content

πŸ’πŸ’πŸ’πŸ’Lazy/async route loading for React Router 4 through System.import

Notifications You must be signed in to change notification settings

zanjs/lazy-route

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’€πŸ’€πŸ’€πŸ’€ fork lazy-route πŸ’€πŸ’€πŸ’€

lazy-route - Lazy route loading for React Router 4 through System.import

Dependencies and requirements

This component only works with React Router 4 and Webpack 2 (because of System.import).

Usage

Installation:

npm

npm install route-lazy

yarn

yarn add route-lazy

How to use with React Router 4:

import {Match} from 'react-router'
import RouteLazy from 'route-lazy'

<Match 
  pattern="/myroute"
  render={(props) => <RouteLazy {...props} component={import('./myComponent')} />}
/>

demo

react-mobx-start

demo router

class RouteComment extends Component {
  render() {
    return (
       <div>
         <Switch> 
          <Route
              exact
              path={RoutePath.home}
              render={props => (
                <RouteLazy {...props} component={import("../pages/home")} />
              )}
            />
          <Route
            path={RoutePath.topics}
            render={props => (
              <RouteLazy {...props} component={import("../pages/topics")} />
            )}
          />
          <Route
            path={RoutePath.histtory}
            render={props => (
              <RouteLazy {...props} component={import("../pages/history")} />
            )}
          />
          <Route
            path={RoutePath.about}
            render={props => (
              <RouteLazy {...props} component={import("../pages/about")} />
            )}
          />
            <Route component={NotFound}/> 
         </Switch> 
        </div>
    );
  }
}

Upcoming features

The component works, but I have yet to add tests and some polish to it, the plan is to add a customizable loader etc.

Thinks

Chih-Hsuan Fan Martin

About

πŸ’πŸ’πŸ’πŸ’Lazy/async route loading for React Router 4 through System.import

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%