1.2.6 • Published 1 year ago

react-hookscout v1.2.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

React Hookscout Router

The modern alternative to react-router.

Tested from React 16.8.1 upwards.

How to install

Well, this is straightforward:

npm i react-hookscout

Documentation

Detailed documentation about how to use the Rosetta router can be found here

A quick example

import {useRoutes} from 'react-hookscout';

const routes = {
    '/': () => <HomePage />,
    '/about': () => <AboutPage />,
    '/products': () => <ProductOverview />,
    '/products/:id': ({id}) => <ProductDetails id={id} />
};
	
const MyApp = () => {
    const routeResult = useRoutes(routes);
    
    return routeResult || <NotFoundPage />;
}

Routes are defined as an object. Keys are the routes, which are matched against the URL, the values need to be functions that are called when a route matches. You may define placeholders in your routes with :something which will be forwarded as props to your function calls so you can distribute them to your components.

The hook will return whatever the route function returned, so you may also return strings, arrays, React fragments, null - whatever you like.

1.2.6

1 year ago

1.2.5

1 year ago