Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hookrouter-react

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hookrouter-react

A hook based router for React

  • 1.3.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9
increased by28.57%
Maintainers
1
Weekly downloads
 
Created
Source

hookrouter-react

NOTE: This is a patched version from the original hookrouter package.

This package does the following:

  • fixes syntax errors
  • uses rollup instead of webpack
  • integrates eslint
  • integrates babel

The modern alternative to react-router.

Tested from React 16.8.1 upwards.

How to install

Well, this is straightforward:

npm i hookrouter-react

Documentation

Detailed documentation about how to use hookrouter can be found here

A quick example

import {useRoutes} from 'hook-router';

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.

FAQs

Package last updated on 17 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc