Socket
Socket
Sign inDemoInstall

@reach/router

Package Overview
Dependencies
Maintainers
4
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@reach/router

Next generation Routing for React.


Version published
Weekly downloads
488K
decreased by-12.8%
Maintainers
4
Weekly downloads
 
Created

What is @reach/router?

@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.

What are @reach/router's main functionalities?

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;

Other packages similar to @reach/router

Keywords

FAQs

Package last updated on 25 Jun 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