fix(router-core): make navigate publicHref Aware #6205
main fromrefs/pull/6205/head·merged by nlynzaad(GitHub profile, opens in a new tab) This PR addresses issues raised in #5200 and #5202.
Following #6201 this replaces #6157 as this PR makes better use of the distinctions between href and publicHref.
We also add an e2e test on router to test for redirects with and without reloadDocument = true.
Summary by CodeRabbit#
New Features
- Added two new redirect routes for quick navigation (/redirect and /redirectReload).
- Support for redirects that optionally trigger a full page reload.
- Navigation now accepts an optional public-facing URL to handle rewritten or absolute navigations.
Tests
- Added end-to-end tests verifying redirect behavior and basepath handling (with and without full reload).
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core
View your CI Pipeline Execution ↗ for commit 386177d8074fa08f6c7f607243ff2dcc43431e83
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 5m 40s View ↗
☁️ Nx Cloud last updated this comment at
2025-12-23 23:34:43UTCActionable comments posted: 1
🧹 Nitpick comments (2)
packages/router-core/src/link.ts (1)
356-356: Add JSDoc documentation for the newpublicHrefproperty.For consistency with other properties in the
NavigateOptionPropsinterface (e.g.,hashScrollIntoView,replace,resetScroll), please add JSDoc comments explaining:- What
publicHrefis used for - When it should be provided
- How it differs from the regular
hrefproperty
📝 Suggested documentation
reloadDocument?: boolean /** + * The public-facing URL to use when performing a full document navigation. + * This is used when the internal routing path differs from the public URL (e.g., when using URL rewriting or basepath transformations). + * If not provided, the router will compute the public URL from the current location. + * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#publichref) + */ + publicHref?: string + /** * This can be used instead of `to` to navigate to a fully built href, e.g. pointing to an external target. * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#href) */ href?: string - publicHref?: stringpackages/router-core/src/router.ts (1)
2053-2059: Consider clarifying the conditional logic for building location.The condition on line 2053
if (!href || (!publicHref && !hrefIsUrl))could be more explicit. It's building a location when:- No href is provided, OR
- No publicHref is provided AND href is not a URL
This logic works correctly but might benefit from a comment explaining the intent.
💡 Suggested clarification
if (reloadDocument) { + // Build location to compute href/publicHref if either: + // 1. No href provided, or + // 2. We have a relative href but no explicit publicHref if (!href || (!publicHref && !hrefIsUrl)) { const location = this.buildLocation({ to, ...rest } as any) href = href ?? location.url.href publicHref = publicHref ?? location.url.href } const reloadHref = !hrefIsUrl && publicHref ? publicHref : href📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 73315f1b3ed7122df737e99a89659e6a10f8a67f and 538e21881c6d5c1f92bc501c70b3c49ce371ed9f.
📒 Files selected for processing (7)
e2e/react-router/basepath-file-based/src/routeTree.gen.tse2e/react-router/basepath-file-based/src/routes/index.tsxe2e/react-router/basepath-file-based/src/routes/redirect.tsxe2e/react-router/basepath-file-based/src/routes/redirectReload.tsxe2e/react-router/basepath-file-based/tests/reload-document.test.tspackages/router-core/src/link.tspackages/router-core/src/router.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript strict mode with extensive type safety for all code
Files:
e2e/react-router/basepath-file-based/src/routes/redirect.tsxpackages/router-core/src/link.tse2e/react-router/basepath-file-based/src/routes/redirectReload.tsxe2e/react-router/basepath-file-based/src/routes/index.tsxpackages/router-core/src/router.tse2e/react-router/basepath-file-based/src/routeTree.gen.tse2e/react-router/basepath-file-based/tests/reload-document.test.ts
**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Implement ESLint rules for router best practices using the ESLint plugin router
Files:
e2e/react-router/basepath-file-based/src/routes/redirect.tsxpackages/router-core/src/link.tse2e/react-router/basepath-file-based/src/routes/redirectReload.tsxe2e/react-router/basepath-file-based/src/routes/index.tsxpackages/router-core/src/router.tse2e/react-router/basepath-file-based/src/routeTree.gen.tse2e/react-router/basepath-file-based/tests/reload-document.test.ts
🧠 Learnings (9)
📓 Common learnings
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: packages/router-core/src/router.ts:2231-2245 Timestamp: 2025-10-01T18:30:26.591Z Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.Learnt from: nlynzaad Repo: TanStack/router PR: 5182 File: e2e/react-router/basic-file-based/tests/non-nested-paths.spec.ts:167-172 Timestamp: 2025-09-22T00:56:53.426Z Learning: In TanStack Router, underscores are intentionally stripped from route segments during path parsing, but preserved in base path segments. This is the expected behavior implemented in PR #5182.Learnt from: nlynzaad Repo: TanStack/router PR: 5182 File: e2e/react-router/basic-file-based/src/routes/non-nested/named/$baz_.bar.tsx:3-5 Timestamp: 2025-09-22T00:56:49.237Z Learning: In TanStack Router, underscores are intentionally stripped from route segments (e.g., `$baz_` becomes `baz` in generated types) but should be preserved in base path segments. This is the correct behavior as of the fix in PR #5182.Learnt from: FatahChan Repo: TanStack/router PR: 5475 File: e2e/react-start/basic-prerendering/src/routes/redirect/$target/via-beforeLoad.tsx:8-0 Timestamp: 2025-10-14T18:59:33.990Z Learning: In TanStack Router e2e test files, when a route parameter is validated at the route level (e.g., using zod in validateSearch or param validation), switch statements on that parameter do not require a default case, as the validation ensures only expected values will reach the switch.📚 Learning: 2025-10-01T18:30:26.591Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: packages/router-core/src/router.ts:2231-2245 Timestamp: 2025-10-01T18:30:26.591Z Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.Applied to files:
e2e/react-router/basepath-file-based/src/routes/redirect.tsxpackages/router-core/src/link.tse2e/react-router/basepath-file-based/src/routes/redirectReload.tsxe2e/react-router/basepath-file-based/src/routes/index.tsxpackages/router-core/src/router.tse2e/react-router/basepath-file-based/src/routeTree.gen.tse2e/react-router/basepath-file-based/tests/reload-document.test.ts
📚 Learning: 2025-12-17T02:17:55.086Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 6120 File: packages/router-generator/src/generator.ts:654-657 Timestamp: 2025-12-17T02:17:55.086Z Learning: In `packages/router-generator/src/generator.ts`, pathless_layout routes must receive a `path` property when they have a `cleanedPath`, even though they are non-path routes. This is necessary because child routes inherit the path from their parent, and without this property, child routes would not have the correct full path at runtime.Applied to files:
packages/router-core/src/link.tse2e/react-router/basepath-file-based/src/routeTree.gen.ts
📚 Learning: 2025-12-21T12:52:35.231Z
Learnt from: Sheraff Repo: TanStack/router PR: 6171 File: packages/router-core/src/new-process-route-tree.ts:898-898 Timestamp: 2025-12-21T12:52:35.231Z Learning: In `packages/router-core/src/new-process-route-tree.ts`, the matching logic intentionally allows paths without trailing slashes to match index routes with trailing slashes (e.g., `/a` can match `/a/` route), but not vice-versa (e.g., `/a/` cannot match `/a` layout route). This is implemented via the condition `!pathIsIndex || node.kind === SEGMENT_TYPE_INDEX` and is a deliberate design decision to provide better UX by being permissive with missing trailing slashes.Applied to files:
packages/router-core/src/router.tse2e/react-router/basepath-file-based/src/routeTree.gen.ts
📚 Learning: 2025-10-01T18:31:35.420Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: e2e/react-start/custom-basepath/src/routeTree.gen.ts:58-61 Timestamp: 2025-10-01T18:31:35.420Z Learning: Do not review files named `routeTree.gen.ts` in TanStack Router repositories, as these are autogenerated files that should not be manually modified.Applied to files:
e2e/react-router/basepath-file-based/src/routeTree.gen.ts
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5402 File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21 Timestamp: 2025-10-08T08:11:47.088Z Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.Applied to files:
e2e/react-router/basepath-file-based/src/routeTree.gen.tse2e/react-router/basepath-file-based/tests/reload-document.test.ts
📚 Learning: 2025-12-06T15:03:07.223Z
Learnt from: CR Repo: TanStack/router PR: 0 File: AGENTS.md:0-0 Timestamp: 2025-12-06T15:03:07.223Z Learning: Applies to **/*.{js,ts,tsx} : Implement ESLint rules for router best practices using the ESLint plugin routerApplied to files:
e2e/react-router/basepath-file-based/src/routeTree.gen.ts
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad Repo: TanStack/router PR: 5732 File: packages/start-client-core/src/client/hydrateStart.ts:6-9 Timestamp: 2025-11-02T16:16:24.898Z Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.Applied to files:
e2e/react-router/basepath-file-based/src/routeTree.gen.ts
📚 Learning: 2025-12-06T15:03:07.223Z
Learnt from: CR Repo: TanStack/router PR: 0 File: AGENTS.md:0-0 Timestamp: 2025-12-06T15:03:07.223Z Learning: Use file-based routing in `src/routes/` directories or code-based routing with route definitionsApplied to files:
e2e/react-router/basepath-file-based/src/routeTree.gen.ts
🧬 Code graph analysis (2)
e2e/react-router/basepath-file-based/src/routes/redirect.tsx (2)
e2e/react-router/basepath-file-based/src/routes/index.tsx (1)
Route(3-5)
e2e/react-router/basepath-file-based/src/routes/redirectReload.tsx (1)
Route(3-8)
e2e/react-router/basepath-file-based/src/routes/redirectReload.tsx (2)
e2e/react-router/basepath-file-based/src/routes/index.tsx (1)
Route(3-5)
e2e/react-router/basepath-file-based/src/routes/redirect.tsx (1)
Route(3-8)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Test
- GitHub Check: Preview
🔇 Additional comments (8)
e2e/react-router/basepath-file-based/tests/reload-document.test.ts (2)
20-28: LGTM! Well-structured test for redirect with basepath.The test correctly verifies that redirects respect the basepath configuration, following the same pattern as the existing navigate test.
30-40: LGTM! Comprehensive coverage for reload document scenario.This test ensures that redirects with
reloadDocument: truealso respect the basepath, which is critical for the publicHref functionality introduced in this PR.e2e/react-router/basepath-file-based/src/routes/redirect.tsx (1)
1-12: LGTM! Standard redirect route implementation.The route correctly uses
beforeLoadto redirect to/aboutbefore rendering. The component definition is appropriate even though it won't be rendered, as it's required by the route definition.e2e/react-router/basepath-file-based/src/routes/redirectReload.tsx (1)
1-12: LGTM! Correctly implements redirect with document reload.This route properly tests the scenario where a redirect occurs with
reloadDocument: true, which is essential for verifying the publicHref handling introduced in this PR.packages/router-core/src/router.ts (3)
2032-2050: LGTM! Good handling of absolute URLs and reloadDocument.The logic correctly:
- Detects absolute URLs using URL constructor
- Automatically sets
reloadDocument: truefor absolute URLs - Handles external navigation scenarios properly
2061-2078: LGTM! Proper blocker handling for external navigation.The implementation correctly checks navigation blockers even for external URLs (unless
ignoreBlockeris set), which maintains consistent blocker behavior across all navigation types.
2080-2084: LGTM! Correct usage of publicHref for document reload.The code properly uses
reloadHref(which preferspublicHrefwhen available) for bothwindow.location.replace()andwindow.location.hrefassignments, ensuring the public-facing URL is used for full page navigations.e2e/react-router/basepath-file-based/src/routeTree.gen.ts (1)
1-113: Autogenerated file - no review needed.This file is automatically generated by TanStack Router (as indicated by the header comment). The changes correctly reflect the new
/redirectand/redirectReloadroutes added in this PR.e2e/react-router/basepath-file-based/src/routes/index.tsx lines 22 to 42Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -22 +22,21 @@22+ </button>{' '}23+ <button24+ data-testid="to-redirect-btn"25+ onClick={() =>26+ navigate({27+ to: '/redirect',28+ })29+ }30+ >31+ Navigate to /redirect without document reload32+ </button>{' '}33+ <button34+ data-testid="to-redirect-reload-btn"35+ onClick={() =>36+ navigate({37+ to: '/redirectReload',38+ })39+ }40+ >41+ Navigate to /about with document reload2242 </button>⚠️ Potential issue | 🟡 Minor
Clarify button text for the redirectReload navigation.
The button on line 41 has text "Navigate to /about with document reload", which is misleading since it actually navigates to
/redirectReload. While the route will eventually redirect to/aboutwithreloadDocument: true, the button text should reflect what it directly does.🔎 Suggested fix
> Navigate to /redirect without document reload </button>{' '} <button data-testid="to-redirect-reload-btn" onClick={() => navigate({ to: '/redirectReload', }) } > - Navigate to /about with document reload + Navigate to /redirectReload (redirects to /about with document reload) </button>📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Suggested change22- </button>{' '}23- <button24- data-testid="to-redirect-btn"25- onClick={() =>26- navigate({27- to: '/redirect',28- })29- }30- >31- Navigate to /redirect without document reload32- </button>{' '}33- <button34- data-testid="to-redirect-reload-btn"35- onClick={() =>36- navigate({37- to: '/redirectReload',38- })39- }40- >41- Navigate to /about with document reload42- </button>22+ </button>{' '}23+ <button24+ data-testid="to-redirect-btn"25+ onClick={() =>26+ navigate({27+ to: '/redirect',28+ })29+ }30+ >31+ Navigate to /redirect without document reload32+ </button>{' '}33+ <button34+ data-testid="to-redirect-reload-btn"35+ onClick={() =>36+ navigate({37+ to: '/redirectReload',38+ })39+ }40+ >41+ Navigate to /redirectReload (redirects to /about with document reload)42+ </button>🤖 Prompt for AI Agents
In e2e/react-router/basepath-file-based/src/routes/index.tsx around lines 22 to 42, the button label "Navigate to /about with document reload" is misleading because the onClick navigates to /redirectReload (which later redirects to /about with reload); update the button text to accurately describe the direct action (e.g., "Navigate to /redirectReload with document reload" or "Navigate to /redirectReload (reload)"), keeping wording concise and matching the actual `to` value and reload behavior.✅ Addressed in commit 35b8446
- What
More templates
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-router-react-example-basic-authjs
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-rsc
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
- tanstack-router-solid-example-authenticated-routes
- tanstack-router-solid-example-authenticated-routes-firebase
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-default-search-params
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-basic-virtual-file-based
- tanstack-router-solid-example-basic-virtual-inside-file-based
- tanstack-router-solid-example-deferred-data
- tanstack-router-solid-i18n-paraglide
- tanstack-router-solid-example-kitchen-sink
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-large-file-based
- tanstack-router-solid-example-location-masking
- tanstack-router-solid-example-navigation-blocking
- tanstack-router-solid-example-quickstart
- tanstack-router-solid-example-quickstart-esbuild-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-router-solid-example-quickstart-rspack-file-based
- tanstack-router-solid-example-quickstart-webpack-file-based
- @tanstack/router-solid-mono-simple
- router-solid-mono-simple-lazy
- router-solid-monorepo-solid-query
- tanstack-router-solid-example-scroll-restoration
- tanstack-solid-router-search-validator-adapters
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-authjs
- tanstack-solid-start-example-basic-cloudflare
- tanstack-solid-start-example-basic-netlify
- tanstack-solid-start-example-basic-nitro
- tanstack-start-example-basic-solid-query
- tanstack-solid-start-example-basic-static
- tanstack-solid-start-bun-hosting
- tanstack-solid-start-example-convex-better-auth
- tanstack-solid-start-example-counter
- tanstack-solid-start-i18n-paraglide
- tanstack-solid-start-example-large
- tanstack-solid-start-streaming-data-from-server-functions
- tanstack-solid-start-example-supabase-basic
- tanstack-solid-start-tailwind-v4
- tanstack-router-solid-example-view-transitions
- tanstack-router-solid-example-with-framer-motion
- tanstack-router-solid-example-with-trpc
- tanstack-router-vue-example-basic-jsx
- tanstack-router-vue-example-basic-file-based-jsx
- tanstack-router-vue-example-basic-file-based-sfc
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@6205@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@6205@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@6205@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6205@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@6205@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@6205@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@6205@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@6205@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6205@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6205@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6205@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@6205@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@6205@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@6205@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@6205@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@6205@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@6205@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@6205@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@6205@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@6205@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@6205@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@6205@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@6205@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@6205@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6205@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6205@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6205@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6205@tanstack/start-fn-stubs
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-fn-stubs@6205@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6205@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6205@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@6205@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6205@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6205@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6205@tanstack/vue-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@6205@tanstack/vue-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-devtools@6205@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@6205@tanstack/vue-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6205@tanstack/vue-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6205@tanstack/vue-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6205@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6205commit:
386177d- @@ -353,3 +353,4 @@353353 * @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType#href)354354 */355355 href?: string356+ publicHref?: string
we should not add this here because it's just an internal prop
marked it as internal. checked the .d.ts and confirmed with preview builds its not available in the public facing types.
- @@ -2029,5 +2029,4 @@20292029 *20302030 * @link https://tanstack.com/router/latest/docs/framework/react/api/router/NavigateOptionsType20312031 */2032- navigate: NavigateFn = async ({ to, reloadDocument, href, ...rest }) => {2033- if (!reloadDocument && href) {2032+ navigate: NavigateFn = async ({
can we add the publicHref somehow else as a prop here so we can use it but dont show it in the public API?
marked it as internal. checked the .d.ts and confirmed with preview builds its not available in the public facing types.
schiller-manuel(GitHub profile, opens in a new tab) approved these changes
nlynzaad(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
📝 Walkthrough
Walkthrough#
Adds two file-based redirect routes and tests; and extends RouterCore.navigate with an optional
publicHrefoption, absolute-URL detection, blocker checks for external navigations, and preference forpublicHrefwhen performing document reloads.Changes#
e2e/react-router/basepath-file-based/src/routeTree.gen.tsRedirectRouteandRedirectReloadRoutein route maps, FileRouteTypes, RootRouteChildren, and module augmentation for@tanstack/react-router.e2e/react-router/basepath-file-based/src/routes/redirect.tsx,e2e/react-router/basepath-file-based/src/routes/redirectReload.tsx/redirect(beforeLoad -> redirect to/about) and/redirectReload(beforeLoad -> redirect to/aboutwithreloadDocument: true) routes and simple components.e2e/react-router/basepath-file-based/src/routes/index.tsxe2e/react-router/basepath-file-based/tests/reload-document.test.tsreloadDocument.packages/router-core/src/link.ts,packages/router-core/src/router.tspublicHref?: stringto NavigateOptionProps and extendedRouterCore.navigateto accept/usepublicHref; added absolute-URL detection, external navigation blocker checks, and use ofpublicHref(or fallback) for document reloads.Sequence Diagram(s)#
Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs#
publicHrefreload semantics.Suggested labels#
package: react-routerSuggested reviewers#
Poem#
Pre-merge checks and finishing touches#
❌ Failed checks (1 warning)
@coderabbitai generate docstringsto improve docstring coverage.✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 35b8446f705c4fbe66f7a3d33734fe62dedb80ef and 386177d8074fa08f6c7f607243ff2dcc43431e83.
📒 Files selected for processing (1)
packages/router-core/src/link.ts🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/router-core/src/link.ts**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Files:
packages/router-core/src/link.ts🧠 Learnings (2)
📓 Common learnings
📚 Learning: 2025-10-01T18:30:26.591Z
Applied to files:
packages/router-core/src/link.ts⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
🔇 Additional comments (1)
Comment `@coderabbitai help` to get the list of available commands and usage tips.