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)
orsetRoute(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)