Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Link in parent/layout route with to="." unexpectedly navigates back to parent route #2988

Open
fa-sharp opened this issue Dec 12, 2024 · 2 comments

Comments

@fa-sharp
Copy link

Which project does this relate to?

Router

Describe the bug

In a layout/pathless route, when using a Link that only updates the search params and uses to=".", it is unexpectedly navigating back to a parent route rather than staying on the same route. This was previously working as expected - the behavior appears to have changed somewhere between v1.81.9 - v1.87.9.

Your Example Website or App

https://stackblitz.com/edit/github-7sawyaq2?file=src%2Froutes%2F__root.tsx

Steps to Reproduce the Bug or Issue

I've setup a minimal example using the pre-configured file-based routing example. I added a Link in the root route, that adds foo: "bar" to the search params, and uses the relative path of "." for the to prop. My understanding is that this Link should only update the search params, and the actual route path shouldn't change. However, it always navigates back to the home page. In previous versions of Router (~1.81.9), this was working as expected.

  1. Go to Stackblitz example above
  2. Click on the About page link. The URL correctly changes to /about.
  3. Click on the Update search only link. The URL changes the search param as expected, but it unexpectedly navigates back to the home page /.

Expected behavior

I expect that a Link component with to="." should always stay on the current route, regardless of whether it is part of a layout/pathless route.

Screenshots or Videos

No response

Platform

  • OS: macOS
  • Browser: Chrome
  • Version: 131

Additional context

No response

@schiller-manuel
Copy link
Contributor

Thanks for the great reproducer!
I narrowed it down to v1.81.10, specifically this:

bab07dc

@kavika-1
Copy link

kavika-1 commented Dec 14, 2024

Thanks for filing this, until a fix is provided, we are using a workaround to get the relative pathname to use in from:

  const router = useRouter()
  const currentRoute = router.state?.location?.pathname
  ...
  <Link
        from={currentRoute}
        to="."
        search={...}
  />

This is working for us as a temporary fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants