Skip to content

fix: Make buildLocation aware of non-changing routes #4573

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

Conversation

nlynzaad
Copy link
Contributor

@nlynzaad nlynzaad commented Jul 3, 2025

This is an attempt to resolve #4526 by making buildLocation aware of the fact that even though there is a "to" path the route is not always changing. This is specifically the case with to="." navigations.

This also adds a test largely based on the test provided by amargielewski

fixes #4526

Copy link

nx-cloud bot commented Jul 3, 2025

View your CI Pipeline Execution ↗ for commit 39b9606

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 1m 48s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2025-07-04 22:09:52 UTC

Copy link

pkg-pr-new bot commented Jul 3, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@4573

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@4573

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@4573

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@4573

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@4573

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@4573

@tanstack/react-router-with-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-with-query@4573

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@4573

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@4573

@tanstack/react-start-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-plugin@4573

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@4573

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@4573

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@4573

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@4573

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@4573

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@4573

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@4573

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@4573

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@4573

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@4573

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@4573

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@4573

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@4573

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@4573

@tanstack/solid-start-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-plugin@4573

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@4573

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@4573

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@4573

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@4573

@tanstack/start-server-functions-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-client@4573

@tanstack/start-server-functions-fetcher

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-fetcher@4573

@tanstack/start-server-functions-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-functions-server@4573

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@4573

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@4573

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@4573

commit: 39b9606

@nlynzaad nlynzaad marked this pull request as draft July 3, 2025 18:10
nlynzaad and others added 3 commits July 3, 2025 20:26
…ects-to-base-path' into resolve-navigate({-to-.-})-redirects-to-base-path

# Conflicts:
#	packages/router-core/src/router.ts
@nlynzaad nlynzaad marked this pull request as ready for review July 3, 2025 18:48
@schiller-manuel
Copy link
Contributor

schiller-manuel commented Jul 4, 2025

looks good! can you please add a test that changes path params like this navigate({to: '.', params: {foo : 'bar'}})?

@nlynzaad
Copy link
Contributor Author

nlynzaad commented Jul 4, 2025

great. I've added the test. will send through momentarily

nlynzaad and others added 4 commits July 4, 2025 23:37
…ects-to-base-path' into resolve-navigate({-to-.-})-redirects-to-base-path

# Conflicts:
#	packages/router-core/src/router.ts
@schiller-manuel
Copy link
Contributor

schiller-manuel commented Jul 4, 2025

an index route cannot have child routes really. although this might somehow work it's better to use a different structure.
in that case just move the component from the posts index route to posts route

@schiller-manuel
Copy link
Contributor

can you please use getByTestId instead of role /text based lookup? we write new tests based on this (and hopefully port the old ones eventually)

@nlynzaad
Copy link
Contributor Author

nlynzaad commented Jul 4, 2025

done and done

@schiller-manuel schiller-manuel changed the title Fix: Make buildLocation aware of non-changing routes fix: Make buildLocation aware of non-changing routes Jul 5, 2025
@schiller-manuel
Copy link
Contributor

thanks a lot!

@schiller-manuel schiller-manuel merged commit 09e152a into TanStack:main Jul 5, 2025
5 checks passed
@checkerschaf
Copy link

@nlynzaad Thanks for looking into this! This code is still failing for me with the latest version 1.124.2.

Example:

const shareRecipeId = useSearch({
  from: "/$lang/_app",
  select: (search) => search._shareRecipeId,
});

navigate({
  to: ".",
  search: (prev) => ({
    ...prev,
    _shareRecipeId: undefined,
  }),
  resetScroll: false,
});

Instead of remaining on the same page, it navigates to /$lang. The route file is located at routes/$lang/route.ts, which may be helpful.

Do you have any insights into why this is causing problems? If not, I can look into the test in the next few days. Thanks!

@nlynzaad nlynzaad deleted the resolve-navigate({-to-.-})-redirects-to-base-path branch July 5, 2025 09:10
@nlynzaad
Copy link
Contributor Author

nlynzaad commented Jul 5, 2025

@checkerschaf from the looks of it, it should be covered by the update. However it differs slightly to the previous in the it rerouted to "/" in your case it's back to "/$lang" and might have small detail that was missed.

Please can you open a new issue with a reproducible example or test.

@checkerschaf
Copy link

@nlynzaad Thank you. I've created an issue with a reproducible example: #4580

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

Successfully merging this pull request may close these issues.

Regression: navigate({ to: "." }) redirects to base path after update to v1.121.34
3 participants