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

@types/react-router-dom

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@types/react-router-dom

TypeScript definitions for react-router-dom

  • 5.3.3
  • ts3.8
  • ts3.9
  • ts4.0
  • ts4.1
  • ts4.2
  • ts4.3
  • ts4.4
  • ts4.5
  • ts4.6
  • ts4.7
  • ts4.8
  • ts4.9
  • ts5.0
  • ts5.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created

What is @types/react-router-dom?

The @types/react-router-dom package provides TypeScript type definitions for the react-router-dom library, which is a standard library for routing in React applications. It enables strong typing for components and functions from react-router-dom, enhancing development experience by offering compile-time type checking and IntelliSense support in code editors.

What are @types/react-router-dom's main functionalities?

BrowserRouter

Defines a Router using the BrowserRouter component, setting up navigation and routes for a simple application.

import { BrowserRouter as Router, Route, Link } from 'react-router-dom';

function App() {
  return (
    <Router>
      <div>
        <nav>
          <ul>
            <li>
              <Link to='/'>Home</Link>
            </li>
            <li>
              <Link to='/about'>About</Link>
            </li>
          </ul>
        </nav>

        <Route path='/' exact component={Home} />
        <Route path='/about' component={About} />
      </div>
    </Router>
  );
}

Route Parameters

Demonstrates how to use route parameters with the useParams hook to display dynamic content based on the URL.

import { BrowserRouter as Router, Route, Link } from 'react-router-dom';

function Post() {
  let { postId } = useParams();
  return <div>Now showing post {postId}</div>;
}

function App() {
  return (
    <Router>
      <div>
        <Link to='/post/123'>Post 123</Link>
        <Route path='/post/:postId' component={Post} />
      </div>
    </Router>
  );
}

Nested Routes

Shows how to implement nested routes using the useRouteMatch hook to match parts of the URL and render accordingly.

import { BrowserRouter as Router, Route, Link, useRouteMatch } from 'react-router-dom';

function Topics() {
  let { path, url } = useRouteMatch();
  return (
    <div>
      <ul>
        <li>
          <Link to={`${url}/components`}>Components</Link>
        </li>
        <li>
          <Link to={`${url}/props-v-state`}>Props v. State</Link>
        </li>
      </ul>

      <Route path={`${path}/:topicId`} component={Topic} />
    </div>
  );
}

Other packages similar to @types/react-router-dom

FAQs

Package last updated on 18 Jan 2022

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