dahlia-router
v1.4.1
Published
Router for Dahlia
Downloads
84
Readme
dahlia-router
Installation
yarn add dahlia-routerUsage
import React from 'react'
import ReactDOM from 'react-dom'
import { Router, Link } from 'dahlia-router'
const Home = () => (
<div>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
<h1>Home</h1>
</div>
)
const About = () => (
<div>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
<h1>About</h1>
</div>
)
const NotFound = () => <div>404 not found</div>
const routes = [
{
path: '/',
component: Home,
},
{
path: '/about',
component: About,
},
{
path: '**',
component: NotFound,
},
]
const App = () => <Router routes={routes} />
ReactDOM.render(<App />, document.getElementById('root'))Interceptor
import { navigate, intercept } from 'dahlia-router'
intercept((ctx, next) => {
if (ctx.to === '/') {
navigate('/dashboard')
} else {
return next()
}
})