0.1.9 • Published 3 years ago

react-lazy-router v0.1.9

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

React Lazy Router

Summary

Provides the ability to lazy-load react router route components. It's a wrapper over react-router-dom providing code-splitting capability.

Getting started

npm install react-lazy-router

Usage

import React from "react";
import { BrowserRouter, Route, Switch, Link } from "react-lazy-router";

const Home = React.lazy(() => import("./Home"));
const Hello = React.lazy(() => import("./Hello"));

const Loading = <p>Loading...</p>;

const App = () => {
  return (
    <BrowserRouter>
      <Link to="/">Home</Link> <Link to="/hello">Hello</Link>
      <Switch>
        <Route path="/" component={Home} fallback={Loading} exact />
        <Route path="/hello" fallback={Loading} exact>
          <Hello name="there" />
        </Route>
      </Switch>
    </BrowserRouter>
  );
};

How it works

  • Exports everything from react-router-dom by default
  • Overwrites the Route component by wrapping the original Route in React.Suspense

Sandbox

0.1.8

3 years ago

0.1.7

3 years ago

0.1.9

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago