router icon indicating copy to clipboard operation
router copied to clipboard

<Link to="."> navigates to parent location when it is in a parent route

Open vcarel opened this issue 3 years ago • 0 comments

Describe the bug

I have a Link like this:

<Link to="." search={{ someParams: true }}>My link</Link>

According to the documentation, it should navigate to current location + ?someParams=true. e.g.: /foobar?someParams=true if my current location is /foobar

However, when this link is in a parent route, it navigates to the parent location instead of staying on the same location (see the example app).

Your Example Website or App

https://stackblitz.com/edit/react-ts-cqow59?file=index.tsx

Steps to Reproduce the Bug or Issue

  1. Click on "Goto foo"
  2. Click on the "Stay here and add params" INSIDE the Foo child -> it stays on the current location
  3. Click on the "Stay here and add params" OUTSIDE the Foo child -> it navigates to "."

Expected behavior

<Link to="."> should always stay on the current location, wherever it is in the React tree.

Screenshots or Videos

No response

Platform

  • OS: [e.g. macOS, Windows, Linux]
  • Browser: [e.g. Chrome, Safari, Firefox]
  • Version: [e.g. 91.1]

Additional context

No response

vcarel avatar Apr 22 '22 09:04 vcarel