vlnck-router v0.0.3
vlnck router
This is a simple router for the vlnck project for React.
Installation
npm install --save vlnck-router
Usage
import React from 'react'
import { Router, Route, Link } from 'vlnck-router'
const Home = () => (
<div>
<h2>Home</h2>
<Link to="/about">About</Link>
</div>
)
const About = () => (
<div>
<h2>About</h2>
<Link to="/">Home</Link>
</div>
)
const App = () => (
<Router>
<Route exact path="/" component={Home} />
<Route path="/about" component={About} />
</Router>
)
API
Router
The Router
component is the main component of the router. It should be used as a wrapper for all the routes.
Props
children
- The routes of the router. It should be an array ofRoute
components.routes
- An array of routes. Each route should be an object with the following properties:defaultComponent
- The component to render when no route is matched.
Route
The Route
component is used to define a route. It should be used as a child of the Router
component.
Props
path
- The path of the route. It can be a string or a regular expression.Component
- The component to render when the route is matched.
Link
The Link
component is used to create links to other routes. It should be used as a child of the Router
component.
Props
to
- The path of the route to link to.children
- The content of the link.target
- The target of the link....props
- Any other props will be passed to thea
element.