Declarative router component for React
Clone or download
Pull request Compare This branch is 237 commits behind STRML:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

React Router Component

React router component allows you to define routes in your React application in a declarative manner, directly as a part of your component hierarchy.

Usage is as simple as just returning a configured router component from your component's render() method:

  <Location path="/" handler={MainPage} />
  <Location path="/users/:username" handler={UserPage} />

Alternatively, if you don't prefer JSX:

  Location({path: "/", handler: MainPage}),
  Location({path: "/users/:username", handler: UserPage}))

Having routes defined as a part of your component hierarchy allows to dynamically reconfigure routing based on your application state. For example you can return a different set of allowed locations for anonymous and signed-in users.

React router component can dispatch based on location.pathname or location.hash if browser doesn't support History API.

Furthermore it provides advanced features like support for full page server side rendering, multiple routers on the same page, contextual routers and support for async components.

Its functionality is tested using Saucelabs on all modern browsers (IE >= 9, Chrome >= 27, Firefox >= 25, Safari >= 6 and Mobile Safari on iPhone and iPad >= 6).

Its size is about 3.5kb gzipped.


React router component is packaged on npm:

% npm install react-router-component

See docs for the usage.