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

itsy-bitsy-router

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

itsy-bitsy-router

Small and opinionated routing solution for React

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by66.67%
Maintainers
1
Weekly downloads
 
Created
Source

Itsy bitsy router

Itsy bitsy router is a very opiniated solution for routing in react applications. It is not compatible with IE and never will be.

Install

You know the drill.

yarn add itsy-bitsy-router

Usage

You will need to declare a router before anything else with useRoutes().

const Router = useRoutes(
  [
    { path: "/login", element: <Login /> },
    { path: "/user/:id", element: <User /> },
  ],
  <FourOhFour />
);

return <Router />;

You can optionally pass a render prop to the router. It is used when your app wants a default layout component, giving the route children as the children prop.

Navigation

To navigate inside your app using anchor links, there is still the need for a <Link> component,

return (
  <Link to="/user/synecdokey" state={{ from: "page1" }}>
    My profile
  </Link>
);

Since the browser history API provides no way to listen to history.pushState() nor history.replaceState() at the moment, you will need useNavigate() to handle navigation.

const Button = () => {
  const navigate = useNavigate();
  return <button onClick={() => navigate("/this-url")}>Click me</button>;
};

To navigate programatically, you can use history.back() and history.forward(). They will work as expected, without the need for some useHistory() shenanigans.

Access data

useParams() is used for the parameters you provided in the url.

const { id } = useParams();

To access the route state, it's all in history.state.

A useLocation() hook is provided, it will give you every property of the window.location object.

const { pathname, search } = useLocation();

FAQs

Package last updated on 10 Jul 2020

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