DEV Community

moogoo
moogoo

Posted on

2 2

React Router 6 send data from link to target page

use Link, useLocation from React-Router 6, send my filterList data from list to detail page.

After enter filter in list page, click on row and go to detail page, then we can go back to list page with filters we added.

import {
  Link as RouterLink,
} from "react-router-dom";
import { useLocation } from "react-router";
Enter fullscreen mode Exit fullscreen mode

List page:

<Button
  variant="contained"
  color="primary"
  size="small"
  style={{ marginLeft: 16 }}
  component={RouterLink}
  state={{ filterList: state.filterList }}
  to= {`/collections/${params.row.id}`}
>
  Edit
</Button>
Enter fullscreen mode Exit fullscreen mode

Detail page:

<Button
  variant="outlined"
  startIcon={<KeyboardBackspaceIcon />}
  to="/collections"
  state={{filterList: location.state.filterList}}
  component={RouterLink}
>
  back to list
</Button>
Enter fullscreen mode Exit fullscreen mode

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay