Reactjs

How to pass state or data in react-router v6

Pass data from one component to another component with react-router (v6) Link Component.

Rajdeep Singh
FrontEnd web
Published in
3 min readMar 17, 2022

--

How to pass state or data in react-router v6
How to pass state or data in react-router v6

The react-router is the best library to handle routing in reactjs. With a react-router, you pass state or data from one component to another component to use the react-router Link component.

Data pass more quickly in the new version of react-router (v6). For example, you can pass an object's data from one component to another.

You can play with code in code sandbox Browser base Ide.

Play with code

Steps

  1. Pass Data
  2. Access data

Pass Data

  1. First step
  2. Second step
  3. Third step

First Step

The first step import the Link Component in react-router-dom

import { Link } from "react-router-dom";

--

--

Rajdeep Singh
FrontEnd web

JavaScript | TypeScript | Reactjs | Nextjs | Rust | Biotechnology | Bioinformatic | Frontend Developer | Author | https://linktr.ee/officialrajdeepsingh