
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
@reach/router
Advanced tools
@reach/router is a small, simple, and accessible routing library for React applications. It focuses on providing a straightforward API for handling client-side routing with an emphasis on accessibility and ease of use.
Basic Routing
This code demonstrates basic routing with @reach/router. It sets up two routes, '/' and '/about', and links to them using the Link component.
import React from 'react';
import { Router, Link } from '@reach/router';
const Home = () => <div>Home</div>;
const About = () => <div>About</div>;
const App = () => (
<div>
<nav>
<Link to="/">Home</Link>
<Link to="/about">About</Link>
</nav>
<Router>
<Home path="/" />
<About path="/about" />
</Router>
</div>
);
export default App;
Nested Routing
This code demonstrates nested routing with @reach/router. It sets up a parent route '/dashboard' with nested routes '/dashboard/profile' and '/dashboard/settings'.
import React from 'react';
import { Router, Link } from '@reach/router';
const Dashboard = ({ children }) => <div>Dashboard {children}</div>;
const Profile = () => <div>Profile</div>;
const Settings = () => <div>Settings</div>;
const App = () => (
<div>
<nav>
<Link to="/dashboard/profile">Profile</Link>
<Link to="/dashboard/settings">Settings</Link>
</nav>
<Router>
<Dashboard path="/dashboard">
<Profile path="profile" />
<Settings path="settings" />
</Dashboard>
</Router>
</div>
);
export default App;
Dynamic Routing
This code demonstrates dynamic routing with @reach/router. It sets up a route '/user/:userId' where ':userId' is a dynamic segment that can match any user ID.
import React from 'react';
import { Router, Link } from '@reach/router';
const User = ({ userId }) => <div>User ID: {userId}</div>;
const App = () => (
<div>
<nav>
<Link to="/user/1">User 1</Link>
<Link to="/user/2">User 2</Link>
</nav>
<Router>
<User path="/user/:userId" />
</Router>
</div>
);
export default App;
React Router is a widely-used routing library for React applications. It offers a more extensive API compared to @reach/router and includes features like nested routes, route guards, and more. It is highly customizable and has a larger community and ecosystem.
Wouter is a minimalist routing library for React. It is very lightweight and focuses on simplicity and performance. While it lacks some of the advanced features of @reach/router and react-router, it is a good choice for small projects or when performance is a critical concern.
Navi is a routing library for React that emphasizes data-driven routing. It allows you to define routes that can fetch data, handle redirects, and more. Navi is more complex than @reach/router but offers powerful features for handling data fetching and route transitions.
Next Generation Routing for React
You can also find the docs in the website directory.
MIT License Copyright (c) 2018-present, Ryan Florence
v1.3.4
FAQs
Next generation Routing for React.
The npm package @reach/router receives a total of 1,170,988 weekly downloads. As such, @reach/router popularity was classified as popular.
We found that @reach/router demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers 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
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.