1.0.5 • Published 5 years ago
exmg-react-router v1.0.5
exmg-react-router
Hash based router for react.
Demo
TODO Check out the demo.
TODO Add animated example <div className={ match ? 'route-is-active' : '' }> ?
Install
npm install exmg-react-router
yarn add exmg-react-router
Usage
Example
import React from 'react';
import ReactDOM from 'react-dom';
import { RouterProvider, Route, Link } from 'exmg-react-router';
ReactDOM.render(
<RouterProvider>
<div className="body">
<Route path="/" exact>
<h1>Home</h1>
</Route>
<Route path="/hello/:name">
{ (match, params) => (match && <h1>Hello { params.name }</h1>) }
</Route>
</div>
<footer>
<Link to="/">Home</Link>
<Link to="/hello/World!">Hello World</Link>
</footer>
</RouterProvider>,
document.getElementById('app')
);
Example sub routes
import React from 'react';
import ReactDOM from 'react-dom';
import { RouterProvider, Route, Link } from 'exmg-react-router';
ReactDOM.render(
<RouterProvider>
<div className="body">
<Route path="/" exact>
<h1>Home</h1>
</Route>
<Route path="/foo">
{ /* Routes will inherit path, so absolute path will be /foo */ }
<Route path="/" exact>
<h1>Foo /</h1>
</Route>
{ /* And /foo/bar */ }
<Route path="/bar" exact>
<h1>Foo /bar</h1>
</Route>
{ /* Links have absolute path */ }
<Link to="/foo">
Foo /
</Link>
<Link to="/foo/bar">
Foo /bar
</Link>
</Route>
</div>
<footer>
<Link to="/">Home</Link>
<Link to="/foo">Hello World</Link>
</footer>
</RouterProvider>,
document.getElementById('app')
);
Props
RouterProvider
type: ?String
default 'hash
'. Optionsbrowser
,hash
ormemory
Route
children: ?JSX.Element
.exact: ?Boolean
defaultfalse
.exclude: ?Boolean
defaultfalse
. Exclude component from notFound match.notFound: ?Boolean
defaultfalse
.path: String
. When<Route />
is nested, path props of parent route will be automagically be prepended.
Link
activeClassName: ?String
default'is-active'
children: ?JSX.Element
defaultnull
className: ?String
default'link'
exact: ?Boolean
defaultfalse
onClick: ?Function
.replace: ?Boolean
defaultfalse
to: String
2.0.0-alpha.3
5 years ago
2.0.0-alpha.2
5 years ago
2.0.0-alpha.1
5 years ago
2.0.0-alpha.0
5 years ago
2.0.0-3
6 years ago
2.0.0-2
6 years ago
2.0.0-1
6 years ago
1.0.5
6 years ago
1.0.4
6 years ago
1.0.3
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago