All Projects → palmerhq → Router Suspense

palmerhq / Router Suspense

Licence: mit
The suspense-friendly minimalistic sister of React Router 4.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Router Suspense

React Bootstrap Webpack Starter
ReactJS 16.4 + new React Context API +react Router 4 + webpack 4 + babel 7+ hot Reload + Bootstrap 4 + styled-components
Stars: ✭ 103 (-20.16%)
Mutual labels:  react-router
React Redux Auth0 Kit
Minimal starter boilerplate project with CRA, React, Redux, React Router and Auth0 authentication
Stars: ✭ 115 (-10.85%)
Mutual labels:  react-router
Eos Dapp
Game Dapp Demo using EOS and React
Stars: ✭ 119 (-7.75%)
Mutual labels:  react-router
Dva Boot Admin
🍰 react admin dashboard ui LANIF-ADMIN --- react 16 + react-router 4 + dva 2 + antd 4 后台管理 脚手架
Stars: ✭ 1,553 (+1103.88%)
Mutual labels:  react-router
Rrc
React Router v4 helper components
Stars: ✭ 112 (-13.18%)
Mutual labels:  react-router
React Redux Starter
A basic template that consists of the essential elements that are required to start building a Single Page Application using React, React Router, Redux, Bootstrap 4, Sass, and Webpack
Stars: ✭ 116 (-10.08%)
Mutual labels:  react-router
Libreact
NO LONGER MAINTAINED - SEE https://github.com/streamich/libreact INSTEAD
Stars: ✭ 100 (-22.48%)
Mutual labels:  react-router
Favesound Redux
🎶 A SoundCloud Client in React + Redux running in production. Live Demo and Source Code to explore React + Redux as a beginner.
Stars: ✭ 1,586 (+1129.46%)
Mutual labels:  react-router
Universal React Redux
🧐 A sensible universal starter kit for React + Redux
Stars: ✭ 112 (-13.18%)
Mutual labels:  react-router
React Router Transitions
Easily handle transitions in your React application 🍃
Stars: ✭ 117 (-9.3%)
Mutual labels:  react-router
Mirror
A simple and powerful React framework with minimal API and zero boilerplate.
Stars: ✭ 1,445 (+1020.16%)
Mutual labels:  react-router
React Koa Login
koa2 + react + react-router(4.0) + redux + webpack + antd
Stars: ✭ 109 (-15.5%)
Mutual labels:  react-router
Reeakt
A modern React boilerplate to awesome web applications
Stars: ✭ 116 (-10.08%)
Mutual labels:  react-router
React Login
A client side implementation of authentication using react.js for my blog on medium. This is the second part of my previous blog on how to implement scalable node.js server.
Stars: ✭ 105 (-18.6%)
Mutual labels:  react-router
Asos
A React Native Clone of the popular ASOS App
Stars: ✭ 122 (-5.43%)
Mutual labels:  react-router
Koa Mobx React Starter
A straightforward starter for Node javascript web projects. Using Koa, MobX and ReactJS (with universal / isomorphic server rendering)
Stars: ✭ 102 (-20.93%)
Mutual labels:  react-router
Go Postgres Jwt React Starter
A go, gin, and postgres API with jwt auth, complete with a react frontend
Stars: ✭ 115 (-10.85%)
Mutual labels:  react-router
React Redux Graphql Apollo Bootstrap Webpack Starter
react js + redux + graphQL + Apollo + react router + hot reload + devTools + bootstrap + webpack starter
Stars: ✭ 127 (-1.55%)
Mutual labels:  react-router
Cwg React Starter
Pre-configured and Ready to use React Starter App. To save time in settings things up for new project. Almost everything needed is already configured. Just clone and start developing without wasting time in doing same stuffs for every project. (#codewithghazi)
Stars: ✭ 122 (-5.43%)
Mutual labels:  react-router
React Router Active Component
Factory function for React components which are active for a particular React Router route
Stars: ✭ 116 (-10.08%)
Mutual labels:  react-router

Router Suspense

A suspense-friendly minimalistic sister of React Router.

npm i router-suspense

As of now, this is a very basic router that works in async-land.

Playing with Suspense

This router will work in React 15+. However, If you want to play around with suspense features, you'll need to enable suspense somehow. That means either building React yourself. Or, using this handy dandy starter we made.

https://github.com/palmerhq/react-suspense-starter

API

The API is basically the core of React Router 4.

<Router>

Exactly the same as RR4's <BrowserRouter>

  • children: React.ReactNode
import React from 'react';
import { unstable_createRoot as createRoot } from 'react-dom';
import { Router } from 'router-suspense';
import App from './App';

const root = createRoot(document.getElementById('app'));

const render = Comp => {
  root.render(
   <Router>
     <Comp />
   </Router>
  );
};

render(App);

<Route>

Render prop component to conditionally render based on the URL. If present, it uses ReactDOM.unstable_deferredUpdates to wait for any suspense jazz to happen on the next route before making the transition.

Route Props

  • render: ((props) => React.ReactNode): Passes history, location, match as a render prop. Only renders when path matches the current location.
  • path: string Path to match. Same as RR4.
  • exact: boolean = false Same as RR4.
import React from 'react'
import { Route, Link } from 'router-suspense'

export const Nav = () => (
  <nav>
    <Link to="/">Home</Link>
    <Link to="/dashboard">Dashboard</Link>
  </nav>
)

export const App = () => (
  <div>
    <nav>
     <Link to="/">Home</Link>
     <Link to="/dashboard">Dashboard</Link>
     <Link to="/user/123">User</Link>
    </nav>
    <Route path="/" exact render={() => <div>Home</div>} />
    <Route path="/dashboard" exact render={() => <div>Dashboard</div>} />
    <Route path="/user/:id" exact render={({ match }) => <div>User {match.params.id} </div>} />
  </div>
)

<Link>

Link works like React Router 4's. You give it a path, it renders an <a>, but does a client-side transition by calling history.push(path) under the hood.

  • to: string The relative path to link to
import React from 'react'
import { Link } from 'router-suspense'

export const Nav = () => (
  <nav>
    <Link to="/">Home</Link>
    <Link to="/dashboard">Dashboard</Link>
  </nav>
)

withRouter(Comp: Component)

A higher-order component that hooks into Router context. Same as RR4.

import React from 'react'
import { Link } from 'router-suspense'

const BackButton = ({ history }) => (
  <div>
    <button onClick={() => history.goBack()}>Back</button>
  </div>
)

export default withRouter(BackButton)

Inspiration

A lot of this code is taken straight from React Router and React Training's MiniRouter lecture.

Authors

Copyright © 2018 The Palmer Group.


MIT License

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].