
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
itsy-bitsy-router
Advanced tools
Itsy bitsy router is a very opiniated solution for routing in react applications. It is not compatible with IE and never will be.
You know the drill.
yarn add itsy-bitsy-router
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.
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.
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
Small and opinionated routing solution for React
We found that itsy-bitsy-router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.