fix(router-core): enhance basePath handling #6157
main frombasepath-redirect·opened This PR addresses issues raised in #5200 and #5202.
It correctly sets the href using the rewrite url path and adds additional logic in the output section of the rewrite to check for paths that is already prefixed with the base path.
We also add an e2e test on router to test for redirects without reloadDocument = true.
This PR replaces #5202 and resolves #5200
Summary by CodeRabbit#
New Features
- Added a "/redirect" route and a UI button that navigates to it; visiting "/redirect" immediately redirects to the About page.
Bug Fixes
- Programmatic redirects now respect the app basepath; location construction aligned with rewritten paths.
Refactor
- Centralized basepath handling to improve consistency.
Tests
- Added and updated end-to-end tests covering basepath, redirect behavior, and navigation assertions.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core
View your CI Pipeline Execution ↗ for commit 9ea0f936057f3e1689e1a812b22b521f2fcc0483
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 10m 31s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 46s View ↗
☁️ Nx Cloud last updated this comment at
2025-12-20 16:18:44UTCActionable comments posted: 2
🧹 Nitpick comments (1)
packages/router-core/src/rewrite.ts (1)
4-5: Duplicate comment lines.Lines 4-5, 23-24, 69-70, and 86-87 contain duplicated JSDoc comments. This appears to be an unintentional copy-paste artifact.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between c906682102dc823014d837a945f680a8acb697e6 and 715c8819f4a25866951c6f40fbde88423d8305ba.
📒 Files selected for processing (7)
e2e/react-router/basepath-file-based/src/routeTree.gen.ts(3 hunks)e2e/react-router/basepath-file-based/src/routes/index.tsx(1 hunks)e2e/react-router/basepath-file-based/src/routes/redirect.tsx(1 hunks)e2e/react-router/basepath-file-based/tests/reload-document.test.ts(1 hunks)e2e/react-start/custom-basepath/tests/navigation.spec.ts(1 hunks)packages/router-core/src/rewrite.ts(1 hunks)packages/router-core/src/router.ts(1 hunks)
🧰 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.tsxe2e/react-router/basepath-file-based/tests/reload-document.test.tse2e/react-router/basepath-file-based/src/routes/index.tsxpackages/router-core/src/rewrite.tse2e/react-start/custom-basepath/tests/navigation.spec.tspackages/router-core/src/router.tse2e/react-router/basepath-file-based/src/routeTree.gen.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.tsxe2e/react-router/basepath-file-based/tests/reload-document.test.tse2e/react-router/basepath-file-based/src/routes/index.tsxpackages/router-core/src/rewrite.tse2e/react-start/custom-basepath/tests/navigation.spec.tspackages/router-core/src/router.tse2e/react-router/basepath-file-based/src/routeTree.gen.ts
🧠 Learnings (11)
📓 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/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: 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: 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.tsxe2e/react-router/basepath-file-based/tests/reload-document.test.tse2e/react-router/basepath-file-based/src/routes/index.tsxpackages/router-core/src/rewrite.tspackages/router-core/src/router.tse2e/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: 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/routes/redirect.tsxe2e/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/routes/redirect.tsxe2e/react-router/basepath-file-based/src/routeTree.gen.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:
e2e/react-router/basepath-file-based/src/routes/redirect.tsxpackages/router-core/src/rewrite.tspackages/router-core/src/router.tse2e/react-router/basepath-file-based/src/routeTree.gen.ts
📚 Learning: 2025-09-22T00:56:49.237Z
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.Applied to files:
packages/router-core/src/rewrite.ts
📚 Learning: 2025-09-22T00:56:53.426Z
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.Applied to files:
packages/router-core/src/rewrite.ts
📚 Learning: 2025-10-09T12:59:02.129Z
Learnt from: hokkyss Repo: TanStack/router PR: 5418 File: e2e/react-start/custom-identifier-prefix/src/styles/app.css:19-21 Timestamp: 2025-10-09T12:59:02.129Z Learning: In e2e test directories (paths containing `e2e/`), accessibility concerns like outline suppression patterns are less critical since the code is for testing purposes, not production use.Applied to files:
e2e/react-start/custom-basepath/tests/navigation.spec.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-start/custom-basepath/tests/navigation.spec.tspackages/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-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
🧬 Code graph analysis (2)
e2e/react-router/basepath-file-based/src/routes/redirect.tsx (1)
e2e/react-router/basepath-file-based/src/routes/index.tsx (1)
Route(3-5)
packages/router-core/src/rewrite.ts (1)
packages/router-core/src/path.ts (1)
joinPaths(12-20)
⏰ 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 (5)
e2e/react-start/custom-basepath/tests/navigation.spec.ts (1)
50-52: LGTM - improved test assertions.Using
waitForURLandtoBeInViewport()is more reliable thanwaitForLoadState('networkidle')and manualisVisible()checks. These changes follow Playwright best practices for navigation testing.e2e/react-router/basepath-file-based/src/routes/redirect.tsx (1)
1-12: LGTM - well-structured redirect route for testing.The route correctly uses
throw redirect()inbeforeLoadto trigger a redirect to/about. This follows TanStack Router's recommended pattern for route-level redirects.packages/router-core/src/router.ts (1)
1761-1771: LGTM - correct basepath handling for href construction.The change correctly derives both
publicHrefandhreffrom the rewritten URL path (which includes the basepath). The internalpathname(line 1767) correctly remains the non-rewritten path for route matching purposes.This aligns with the PR objective to fix href construction by using the rewritten URL path.
e2e/react-router/basepath-file-based/src/routeTree.gen.ts (1)
1-95: Autogenerated file - no review required.This file is autogenerated by TanStack Router and should not be manually modified. The changes correctly reflect the addition of the new
/redirectroute to the route tree structure.Based on learnings,
routeTree.gen.tsfiles are not reviewed as they are automatically generated.e2e/react-router/basepath-file-based/tests/reload-document.test.ts (1)
20-28: LGTM! Solid test coverage for basepath-aware redirects.The new test case correctly verifies that programmatic redirects (via
beforeLoad) respect the configured basepath. The test flow is clear: clicking the redirect button should navigate through/redirect(which redirects to/about) and end up at/app/aboutwith the basepath intact.This complements the existing test nicely by covering the redirect scenario alongside the
reloadDocument=truenavigation case.e2e/react-router/basepath-file-based/src/routes/index.tsx lines 23 to 32Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -20,3 +20,13 @@2020 >2121 Navigate to /about with document reload2222 </button>23+ <button24+ data-testid="to-redirect-btn"25+ onClick={() =>26+ navigate({27+ to: '/redirect',28+ })29+ }30+ >31+ Navigate to /redirect with document reload32+ </button>⚠️ Potential issue | 🟡 Minor
Misleading button label.
The button label states "Navigate to /redirect with document reload" but the
navigate()call does not includereloadDocument: true. Based on the PR objectives (testing redirects whenreloadDocument = trueis not set), the label should reflect this:🔎 Suggested fix
<button data-testid="to-redirect-btn" onClick={() => navigate({ to: '/redirect', }) } > - Navigate to /redirect with document reload + Navigate to /redirect </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 change23- <button24- data-testid="to-redirect-btn"25- onClick={() =>26- navigate({27- to: '/redirect',28- })29- }30- >31- Navigate to /redirect with document reload32- </button>23+ <button24+ data-testid="to-redirect-btn"25+ onClick={() =>26+ navigate({27+ to: '/redirect',28+ })29+ }30+ >31+ Navigate to /redirect32+ </button>🤖 Prompt for AI Agents
In e2e/react-router/basepath-file-based/src/routes/index.tsx around lines 23 to 32 the button text “Navigate to /redirect with document reload” is misleading because navigate() is called without reloadDocument: true; update the button label to accurately reflect that no document reload occurs (for example “Navigate to /redirect (no document reload)” or “Navigate to /redirect without document reload”) so the UI matches the test intent.✅ Addressed in commit 9ea0f93
packages/router-core/src/rewrite.ts lines 63 to 69Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -52,4 +52,12 @@5252 return url5353 },5454 output: ({ url }) => {55+ if (url.pathname === checkBasepath) {56+ url.pathname = '/'57+ } else if (url.pathname.startsWith(checkBasepathWithSlash)) {58+ // Handle basepath with trailing content (e.g., /my-app/users -> /users)59+ url.pathname = url.pathname.slice(normalizedBasepath.length)60+ }61+5562 url.pathname = joinPaths(['/', trimmedBasepath, url.pathname])63+⚠️ Potential issue | 🟠 Major
Case-sensitivity bug in output rewrite.
The output handler compares
url.pathnamedirectly againstcheckBasepath/checkBasepathWithSlash, but these variables may be lowercased whencaseSensitiveis false. Unlike the input handler (lines 41-43), the output handler doesn't normalizeurl.pathnamebefore comparison.🔎 Suggested fix
output: ({ url }) => { + const pathname = opts.caseSensitive + ? url.pathname + : url.pathname.toLowerCase() + - if (url.pathname === checkBasepath) { + if (pathname === checkBasepath) { url.pathname = '/' - } else if (url.pathname.startsWith(checkBasepathWithSlash)) { + } else if (pathname.startsWith(checkBasepathWithSlash)) { // Handle basepath with trailing content (e.g., /my-app/users -> /users) url.pathname = url.pathname.slice(normalizedBasepath.length) } url.pathname = joinPaths(['/', trimmedBasepath, url.pathname]) return url },🤖 Prompt for AI Agents
In packages/router-core/src/rewrite.ts around lines 54 to 63, the output handler compares url.pathname directly to checkBasepath/checkBasepathWithSlash but doesn't normalize url.pathname when caseSensitive is false; update the output handler to mirror the input handler by deriving a comparisonPath (e.g., caseSensitive ? url.pathname : url.pathname.toLowerCase()) and use that comparisonPath for equality and startsWith checks, while keeping slicing/join logic on the original url.pathname as before so the comparisons respect caseSensitivity.✅ Addressed in commit 9ea0f93
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@6157@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@6157@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@6157@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6157@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@6157@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@6157@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@6157@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@6157@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6157@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6157@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6157@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@6157@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@6157@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@6157@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@6157@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@6157@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@6157@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@6157@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@6157@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@6157@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@6157@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@6157@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@6157@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@6157@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6157@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6157@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6157@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6157@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6157@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6157@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@6157@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6157@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6157@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6157@tanstack/vue-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@6157@tanstack/vue-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-devtools@6157@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@6157@tanstack/vue-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6157@tanstack/vue-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6157@tanstack/vue-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6157@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6157commit:
9ea0f93nlynzaad(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Walkthrough#
Adds a file-based "/redirect" route that performs a beforeLoad redirect to "/about", updates route tree and UI to trigger it, adds an e2e test asserting redirects respect the basepath, and refactors router-core rewrite/buildLocation logic to centralize basepath handling and unify rewritten hrefs.
Changes#
e2e/react-router/basepath-file-based/src/routeTree.gen.tsRedirectRouteentry and integrates it into the root route children and all route collections (by fullPath, to, id, path typings).e2e/react-router/basepath-file-based/src/routes/redirect.tsxcreateFileRoute('/redirect')with abeforeLoadthat throws a redirect to/about, and a simple render component; exportsRoute.e2e/react-router/basepath-file-based/src/routes/index.tsxnavigate({ to: '/redirect' }).e2e/react-router/basepath-file-based/tests/reload-document.test.tse2e/react-start/custom-basepath/tests/navigation.spec.ts/posts/1.packages/router-core/src/rewrite.tsremoveBasePathhelper to centralize stripping/handling of basepath and uses it for input/output rewrite logic.packages/router-core/src/router.tsRouterCore.buildLocationnow computesrewrittenFullPathand derives bothpublicHrefandhreffrom it (rewritten pathname + search + hash).Estimated code review effort#
🎯 3 (Moderate) | ⏱️ ~25 minutes
packages/router-core/src/rewrite.ts: correctness of basepath matching, edge cases for exact basepath vs. prefix with slash, and no-regression of existing rewrite behavior.packages/router-core/src/router.ts: ensurerewrittenFullPathcomposition (pathname/search/hash) is correct and consistent for bothhrefandpublicHref.e2e/react-router/basepath-file-based/src/routes/redirect.tsxand the new test: validate redirect semantics (beforeLoad throw) and that tests correctly simulate basepath contexts.Possibly related PRs#
packages/router-core/src/rewrite.tsto centralize basepath handling; overlaps with the newremoveBasePathrefactor.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 (4 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 715c8819f4a25866951c6f40fbde88423d8305ba and 9ea0f936057f3e1689e1a812b22b521f2fcc0483.
📒 Files selected for processing (3)
e2e/react-router/basepath-file-based/src/routes/index.tsx(1 hunks)packages/router-core/src/rewrite.ts(1 hunks)packages/router-core/src/router.ts(1 hunks)🚧 Files skipped from review as they are similar to previous changes (3)
⏰ 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)
Comment `@coderabbitai help` to get the list of available commands and usage tips.