All Projects → zackify → React Router Async Routing

zackify / React Router Async Routing

react router v4 async routing

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to React Router Async Routing

Webpack React Router Redux Es6
webpack2+react+react-router+react-redux+ES6版本的CNode社区
Stars: ✭ 255 (+96.15%)
Mutual labels:  webpack2, react-router
React Mobx React Router4 Boilerplate
React, React-Router 4, MobX and Webpack 2-boilerplate with async routes.
Stars: ✭ 566 (+335.38%)
Mutual labels:  async, react-router
React Dynamic Route Loading Es6
Auto chunking and dynamic loading of routes with React Router and Webpack 2
Stars: ✭ 297 (+128.46%)
Mutual labels:  webpack2, react-router
react-starter
Starter kit for React.
Stars: ✭ 16 (-87.69%)
Mutual labels:  react-router, webpack2
Create React Redux App
This project was bootstrapped with Create React App and Redux, Sass Structure.
Stars: ✭ 46 (-64.62%)
Mutual labels:  async, react-router
react-theme
Production ready Wordpress theme built with React, Redux, Redux-Thunk, Intl, React Router v4, etc... and packaged by Webpack 2. Enjoy!
Stars: ✭ 14 (-89.23%)
Mutual labels:  react-router, webpack2
React Router Server
Server Side Rendering library for React Router v4.
Stars: ✭ 443 (+240.77%)
Mutual labels:  webpack2, react-router
Productivity Frontend
Productivity Application - Kanban Style Productivity Management Application with Customizable Boards, Lists and Cards to Make You More Productive.
Stars: ✭ 234 (+80%)
Mutual labels:  webpack2, react-router
Budgeting
Budgeting - React + Redux + Webpack (tree shaking) Sample App
Stars: ✭ 971 (+646.92%)
Mutual labels:  webpack2, react-router
React Static Complete Website
A complete website built using React JS, With SEO, Code Splitting, Pre-rendering, gzip and more.
Stars: ✭ 16 (-87.69%)
Mutual labels:  webpack2, react-router
react-express-mongodb
基于react全家桶+antd design+webpack2+node+express+mongodb开发的前后台博客系统
Stars: ✭ 26 (-80%)
Mutual labels:  react-router, webpack2
Preact Redux Isomorphic
preact-redux-isomorphic PWA SPA SSR best practices and libraries in under 80kB page size (for live demo click the link below)
Stars: ✭ 85 (-34.62%)
Mutual labels:  webpack2, react-router
react-webpack2-skeleton
Get started with React with Webpack2, React-Router, Redux, Code Splitting and Server Rendering
Stars: ✭ 59 (-54.62%)
Mutual labels:  react-router, webpack2
react-flux-gulp-starter
A universal boilerplate for building React/Flux apps using Gulp and ES6.
Stars: ✭ 46 (-64.62%)
Mutual labels:  react-router, webpack2
react-antd
基于react + redux + immutable + less + ES6/7 + webpack2.0 + fetch + react-router + antd实现的SPA后台管理系统模板
Stars: ✭ 320 (+146.15%)
Mutual labels:  react-router, webpack2
React Antd
基于react + redux + immutable + less + ES6/7 + webpack2.0 + fetch + react-router + antd实现的SPA后台管理系统模板
Stars: ✭ 321 (+146.92%)
Mutual labels:  webpack2, react-router
V2 Universal Js Hmr Ssr React Redux
⚡ (V2) Universal JS - Server Side Rendering, Code Splitting and Hot Module Reloading ⚡
Stars: ✭ 147 (+13.08%)
Mutual labels:  webpack2, react-router
React Redux Styled Hot Universal
react boilerplate used best practices and focus on performance
Stars: ✭ 147 (+13.08%)
Mutual labels:  webpack2, react-router
Redux Webpack Es6 Boilerplate
A starter project for modern React apps with Redux
Stars: ✭ 566 (+335.38%)
Mutual labels:  webpack2, react-router
Simple Universal React Redux
The simplest possible Async Universal React & Redux Boilerplate app, that works on both Mac and Windows
Stars: ✭ 58 (-55.38%)
Mutual labels:  async, react-router

Async Routing

TODO:

  • server render
  • make route config optional

React router v4 is awesome, but one thing is missing! Async routes. There's a couple components out there but they all have the same problem, on route change, the component will return null, then load the page. This makes for an annoying user experience. This package will wait for the bundle before a route change, and also allow you to preload pages!

You must be using webpack 2 along with syntax-dynamic-import to use this package!

Install

npm install react-router-async-routing

Setup

Create a routes file, with the pathname and path to your component files

export default [
  {
    path: '/employers',
    dataPath: 'employers',
  },
  {
    path: '/test/:name',
    dataPath: 'test/index',
  },
]

Create a router file that will export Preload, Link, and Route components for you to use in place of the built in components in v4:

import routes from './routes';
import AsyncSetup from 'react-router-async-routing'

const { Route, Link, Preload } = AsyncSetup(routes, path => import(`./views/${path}.js`));

export { Link, Route, Preload };

The first argument is your routes array, the second is a function that takes a path (the dataPath in the routes file) and load the component according to its location.

Now, render your routes using the components from the file you just created!

import { Route } from './router'

....
{routes.map(route => <Route key={route.path} {...route} />)}

Now, you can link to any page like you're used to, just import { Link } from './router'!

Preloading routes

Note: If you use a service worker, this isn't really needed. Except on older browsers.

If a user is on the homepage, and you'd like to load the about page ahead of time, just render this inside of your homepage:

export const Home = (
  <div>
    <h2>Home</h2>
    <Preload path="/about" />
  </div>  
)

The route will be loaded in the background :)

Custom loading

If you need to do more than just async load a route, you can make your own loader by importing components directly:

import LinkBuilder from 'react-router-async-routing/link'

const CustomLink = LinkBuilder(
  async ({ path }) => await somePromise()
)

The function passed will be awaited on any time a link is clicked.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].