@lolpix/react-hashrouter

0.0.2 • Public • Published

Build Status Coverage Zero Dependencies

react-hashrouter

A simple hashrouter for React with a fluent API

Install

$ npm install --save @lolpix/react-hashrouter

Usage example

import React from 'react';
import Router, {Link} from 'react-hashrouter';

export const Index = ({navigateTo}) => (
  <div>
    <h1>Index page</h1>
    <Link to="/test/1">Go to test #1</Link>
    {/* Or alternatively */}
    <Button type="button" onClick={() => navigateTo('/test/2')}>Go to test #2</Button>
  </div>
);

export const Test = ({testId}) => <h1>Test #{testId}</h1>;

export const App = props => (
  <Router>{routes =>
     routes
         .add('/', Index)
         .add('/test/:testId', Test)
         .fallback(<h1>Not found!</h1>)
  }</Router>
);

Future goals

  • Expose a 'router' object to the routed component
    • addRoute(path, component) or setRoute(path, component) for lazy loaded routes
    • navigateTo(path) as implemented
  • Allow lazy loading of components
    • Accept a Promise inside the routeMapper

License

MIT © Nicolai Süper (nico@k40s.net)

Package Sidebar

Install

npm i @lolpix/react-hashrouter

Weekly Downloads

0

Version

0.0.2

License

MIT

Unpacked Size

15.7 kB

Total Files

12

Last publish

Collaborators

  • nicolaisueper