1.0.3 • Published 4 years ago

react-fast-routes v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

react-fast-routes

Install

npm install react react-router-dom react-fast-routes

Use

import React from 'react'
import {Redirect, HashRouter} from 'react-router-dom'
import {Router, Routes} from 'react-fast-routes'

function RedirectMiddleware(redirect = false, path) {
    return function (Component) {
        return function () {
            if (redirect) {
                return <Redirect to={path}/>
            }

            return <Component/>
        }
    }
}

const routeNames = {
    home: 'home',
    about: 'about',
}

function Home() {
    return (
        <Link to={routes.path(routeNames.home)}>
            {routes.title(routeNames.home)}
        </Link>
    )
}

function About() {
    return 'About'
}

const routes = Routes()
    .set(routeNames.home, 'Home', '/', Home)
    .set(routeNames.about, 'About', '/about', About, [RedirectMiddleware(true, routeNames.home)])

function App() {
    return <Router RouterDriver={HashRouter} routes={routes}/>
}
1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago