-1

hello i'm new to react and react router i have exercice page contain multiple exercices so when i click an exrcice i can get individual exercice

 <Link to={`exercice/${item.id}`} exact path={`exercice/${item.id}`} className={MenuCard.menu}>

with path like this

 http://localhost:3000/exercice/0002 

and i have pricing page wich contain exerice component so when i click an exercice from pricing page i get

http://localhost:3000/pricing/exercice/0002

wich goes to nothing how i can get

http://localhost:3000/exercice/0002 thank you

Moussa Eloifi
  • 15
  • 1
  • 7
  • It's not clear what you mean by "retrieve current path". Can you explain in more detail what you are trying to do and what the issue is and provide a more complete [mcve]? – Drew Reese Sep 29 '22 at 19:21
  • i want to get individual exercice from pricing page wich contain exercice component i get path like this http://localhost:3000/pricing/exercice/0002 i want to get http://localhost:3000/exercice/0002 without "pricing" – Moussa Eloifi Sep 29 '22 at 19:23

1 Answers1

0

You need to add a / at the beginning of your paths so the links are not relative to the current route. As stated in the documentation:

A relative <Link to> value (that does not begin with /) resolves relative to the parent route, which means that it builds upon the URL path that was matched by the route that rendered that <Link>.

Arkellys
  • 5,562
  • 2
  • 16
  • 40