Answer the question
In order to leave comments, you need to log in
Is it possible to somehow pass data with a link?
const arrName = [{name: 'Вася'}, {name: 'Петя'}, {name: 'Коля'}];
<Routes>
<Route path='/name' element={<Name />} />
</Routes>
arrName.map((el) => {
return <Link to='/name' >{el.name}</Link>
})
Answer the question
In order to leave comments, you need to log in
You can pass a name to Link via the state parameter, and get it via Location
dosc: link , location
It is architecturally correct, if you use one route for several elements, indicate explicitly in the URL which item you are referring to
<Route path="invoices" element={<Invoices />}>
<Route path=":invoiceId" element={<Invoice />} />
</Route>
<Link
style={{ display: "block", margin: "1rem 0" }}
to={`/invoices/${invoice.number}`}
key={invoice.number}
>
{invoice.name}
</Link>
import { useParams } from "react-router-dom";
export default function Invoice() {
let params = useParams();
return <h2>Invoice: {params.invoiceId}</h2>;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question