All Projects → atlassian-labs → React Resource Router

atlassian-labs / React Resource Router

Licence: apache-2.0
Configuration driven routing solution for React SPAs that manages route matching, data fetching and progressive rendering

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Resource Router

xRoute
一个小型的前端路由库✈️
Stars: ✭ 36 (-73.53%)
Mutual labels:  spa, router
Miox
Modern infrastructure of complex SPA
Stars: ✭ 374 (+175%)
Mutual labels:  router, spa
Frontexpress
An Express.js-Style router for the front-end
Stars: ✭ 263 (+93.38%)
Mutual labels:  router, spa
Redux Tower
Saga powered routing engine for Redux app.
Stars: ✭ 155 (+13.97%)
Mutual labels:  router, spa
Webvr Webpack Boilerplate
A webvr multi-scenes Single-page application for three.js, webpack
Stars: ✭ 47 (-65.44%)
Mutual labels:  router, spa
Angular
UI-Router for Angular: State-based routing for Angular (v2+)
Stars: ✭ 287 (+111.03%)
Mutual labels:  router, spa
Abstract State Router
Like ui-router, but without all the Angular. The best way to structure a single-page webapp.
Stars: ✭ 288 (+111.76%)
Mutual labels:  router, spa
React
🔼 UI-Router for React
Stars: ✭ 386 (+183.82%)
Mutual labels:  router, spa
Vanilla Ui Router
Simple vanilla JavaScript router
Stars: ✭ 42 (-69.12%)
Mutual labels:  router, spa
Jsoo router
A small router to write easily single-page-app in Js_of_ocaml
Stars: ✭ 24 (-82.35%)
Mutual labels:  router, spa
Sme Router
A lightweight router lib that implement with express route style
Stars: ✭ 112 (-17.65%)
Mutual labels:  router, spa
Routegen
Define your API and SPA routes in one place. Use them anywhere. Only 1.3kb.
Stars: ✭ 86 (-36.76%)
Mutual labels:  router, spa
Universal Router
A simple middleware-style router for isomorphic JavaScript web apps
Stars: ✭ 1,598 (+1075%)
Mutual labels:  router, spa
Weave
A simple CLI router for wiring together several sources behind a single HTTP endpoint
Stars: ✭ 125 (-8.09%)
Mutual labels:  router
Sunengine
SunEngine – site engine with blog, forum and articles sections features support.
Stars: ✭ 130 (-4.41%)
Mutual labels:  spa
Laravel Nuxt
Build a SPA with Laravel and Nuxt.
Stars: ✭ 124 (-8.82%)
Mutual labels:  spa
Router Lab
Lab for Network Principles 2019-2020 fall, 2020-2021 spring and 2020-2021 fall
Stars: ✭ 124 (-8.82%)
Mutual labels:  router
Linux Router
Set Linux as router in one command. Support Internet sharing, redsocks, Wifi hotspot, IPv6. Can also be used for routing VM/containers
Stars: ✭ 129 (-5.15%)
Mutual labels:  router
Luthier Ci
Improved routing, middleware support, authentication tools and more for CodeIgniter 3 framework
Stars: ✭ 129 (-5.15%)
Mutual labels:  router
The router
TheRouter is a software packet router based on DPDK an NPF libraries.
Stars: ✭ 123 (-9.56%)
Mutual labels:  router

react-resource-router logo

react-resource-router

React Resource Router (RRR) is a configuration driven routing solution for React that manages single page application route matching, data fetching and progressive rendering.

Why?

React Resource Router was developed by Atlassian for Jira primarily to improve performance and prepare for compatibility with React's forthcoming Concurrent Mode on both client and server. You can read more about its development and impact here.

Features

  • Fully driven by a static configuration of route objects
  • Each route object contains the following core properties
    • path - the path to match
    • component - the component to render
    • resources - an array of objects containing fetch functions that request the route component's data
  • Data for a route is requested asynchronously and as early as possible, with the page progressively rendering as the requests resolve. This results in quicker meaningful render times
  • Works on both client and server without having to traverse the React tree

Usage

Create your resources

Resources describe and provide the data required for your route. This data is safely stored and accessed via the useResource hook or ResourceSubscriber component.

import { createResource } from 'react-resource-router';
import { fetch } from '../common/utils';

export const homeResource = createResource({
  type: 'HOME',
  getKey: () => 'home-resource-key',
  getData: () => fetch('https://my-api.com/home'),
});

export const aboutResource = createResource({
  type: 'ABOUT',
  getKey: () => 'about-resource-key',
  getData: () => fetch('https://my-api.com/about'),
});

Create your components

These are the React components that get rendered for your routes. As mentioned, they can be wired into the state of your resources via the useResource hook or ResourceSubscriber component.

import { useResource } from 'react-resource-router';
import { aboutResource, homeResource } from '../routes/resources';
import { Loading, Error } from './common';

export const Home = () => {
  const { data, loading, error } = useResource(homeResource);

  if (error) {
    return <Error error={error} />;
  }

  if (loading) {
    return <Loading />;
  }

  return <div>{data.home.content}</div>;
};

export const About = () => {
  const { data, loading, error } = useResource(aboutResource);

  if (error) {
    return <Error error={error} />;
  }

  if (loading) {
    return <Loading />;
  }

  return <div>{data.about.content}</div>;
};

Create your routes

Your route configuration is the single source of truth for your application's routing concerns.

import { Home, About } from '../components';
import { homeResource, aboutResource } from './resources';

export const appRoutes = [
  {
    name: 'home',
    path: '/',
    exact: true,
    component: Home,
    resources: [homeResource],
  },
  {
    name: 'about',
    path: '/about',
    exact: true,
    component: About,
    resources: [aboutResource],
  },
];

Use the Router

Now that you've set up your resources, components and configuration correctly, all you need to do is mount the Router in your react tree with a RouteComponent as a child. It will do the rest!

import {
  Router,
  RouteComponent,
  createBrowserHistory,
} from 'react-resource-router';
import { appRoutes } from './routing/routes';

const App = () => (
  <Router routes={appRoutes} history={createBrowserHistory()}>
    <RouteComponent />
  </Router>
);

Installation

npm install react-resource-router

# or

yarn add react-resource-router

Documentation

Check the docs website or the docs folder.

Examples

You can checkout the repo and play around with the examples we have setup to demonstrate how the API can be used for various use cases.

  1. Clone the repo and install dependencies
  2. Run npm start
  3. Local dev site will launch with all the examples

Thanks

Big thanks to Thinkmill for their involvement in this project.

License

Copyright (c) 2020 Atlassian and others. Apache 2.0 licensed, see LICENSE file.


With ❤️ from Atlassian

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