Trie based React Router in under 1 KB
Table of Contents
About
- Uses Context API and wayfarer for fast routing.
- Tiny footprint (Less than 1 KB gzipped)
- Configurable via history
Install
This project uses node and npm.
$ npm install rout3r
$ # OR
$ yarn add rout3r
Usage
import React from "react";
import ReactDOM from "react-dom";
import { Router, Link } from "rout3r";
const PageOne = () => (
<h2>
Page 1 <Link href="/tiaan?hello=person">go to</Link>
</h2>
);
const PageTwo = props => (
<h2>
Page 2 {props.params.ahhhhh} {JSON.stringify(props.searchParams)}
</h2>
);
const PageThree = props => <h2>Page 3</h2>;
const PageFour = props => <h2>Page 4</h2>;
function App() {
return (
<Router defaultPath="/404">
<PageOne path="/" />
<PageThree path="/foo" />
<PageFour path="/foo/bar" />
<PageTwo path="/:ahhhhh" />
</Router>
);
}
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
Contribute
- Fork it and create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am "Add some feature"
- Push to the branch:
git push origin my-new-feature
- Submit a pull request
License
MIT