0.0.2 • Published 7 years ago

@lolpix/react-hashrouter v0.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
7 years ago

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)