From 23be5f9d773baf950be6ddb2271f55ded775541f Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Wed, 24 Sep 2025 13:59:34 +0900 Subject: [PATCH 01/10] fix(router-core): ensure href proterty uses rewritten URL in buildLocation Signed-off-by: leesb971204 --- packages/router-core/src/router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index 6ca77a4bcd2..136f10dcb89 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -1682,7 +1682,7 @@ export class RouterCore< return { publicHref: rewrittenUrl.pathname + rewrittenUrl.search + rewrittenUrl.hash, - href: fullPath, + href: rewrittenUrl.href.replace(rewrittenUrl.origin, ''), url: rewrittenUrl.href, pathname: nextPathname, search: nextSearch, From 593cb78e4ba6b8dc482762fed50803693870a9b3 Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Wed, 24 Sep 2025 16:06:31 +0900 Subject: [PATCH 02/10] fix(router-core): rewrite examples in RouterOptions for improved clarity Signed-off-by: leesb971204 --- packages/router-core/src/router.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index 136f10dcb89..d9bdfad953d 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -284,12 +284,15 @@ export interface RouterOptions< * ```ts * const router = createRouter({ * routeTree, - * rewrite: rewriteBasepath('/basepath') - * // Or wrap existing rewrite functionality - * rewrite: rewriteBasepath('/basepath', { - * output: ({ url }) => {...}, - * input: ({ url }) => {...}, - * }) + * rewrite: rewriteBasepath({ basepath: '/basepath' }) + * // Or compose with existing rewrite functionality + * rewrite: composeRewrites([ + * rewriteBasepath({ basepath: '/basepath', caseSensitive: true }), + * { + * input: ({ url }) => {...}, + * output: ({ url }) => {...}, + * } + * ]) * }) * ``` * @default '/' From 2b831cf726046177d962aa079fe312beacd954fc Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Fri, 26 Sep 2025 13:37:04 +0900 Subject: [PATCH 03/10] test(react-router): add tests for browser url includes basepath on root route Signed-off-by: leesb971204 --- packages/react-router/tests/router.test.tsx | 66 +++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/packages/react-router/tests/router.test.tsx b/packages/react-router/tests/router.test.tsx index d58dfe2126c..f9f6235f99a 100644 --- a/packages/react-router/tests/router.test.tsx +++ b/packages/react-router/tests/router.test.tsx @@ -2698,6 +2698,72 @@ describe('rewriteBasepath utility', () => { expect(router.state.location.pathname).toBe('/test') }) + it('should handle basepath when accessing root path and maintain basepath in browser URL', async () => { + const rootRoute = createRootRoute({ + component: () => , + }) + + const indexRoute = createRoute({ + getParentRoute: () => rootRoute, + path: '/', + component: () =>
Home
, + }) + + const routeTree = rootRoute.addChildren([indexRoute]) + + const history = createMemoryHistory({ + initialEntries: ['/my-app/'], + }) + + const router = createRouter({ + routeTree, + history, + rewrite: rewriteBasepath({ basepath: '/my-app' }), + }) + + render() + + await waitFor(() => { + expect(screen.getByTestId('home')).toBeInTheDocument() + }) + + expect(router.state.location.pathname).toBe('/') + expect(history.location.pathname).toBe('/my-app/') + }) + + it('should handle basepath option for backward compatibility', async () => { + const rootRoute = createRootRoute({ + component: () => , + }) + + const indexRoute = createRoute({ + getParentRoute: () => rootRoute, + path: '/', + component: () =>
Home
, + }) + + const routeTree = rootRoute.addChildren([indexRoute]) + + const history = createMemoryHistory({ + initialEntries: ['/my-app/'], + }) + + const router = createRouter({ + routeTree, + history, + basepath: '/my-app', + }) + + render() + + await waitFor(() => { + expect(screen.getByTestId('home')).toBeInTheDocument() + }) + + expect(router.state.location.pathname).toBe('/') + expect(history.location.pathname).toBe('/my-app/') + }) + it('should combine basepath with additional input rewrite logic', async () => { const rootRoute = createRootRoute({ component: () => , From a161948e74a9daaa12387d12ec0691b485d5a3ef Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Wed, 1 Oct 2025 08:51:53 +0900 Subject: [PATCH 04/10] fix(router): use publicHref for URL comparisons in Transitioner and router Signed-off-by: leesb971204 --- packages/react-router/src/Transitioner.tsx | 8 ++++---- packages/router-core/src/router.ts | 14 ++++++++++---- packages/solid-router/src/Transitioner.tsx | 8 ++++---- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/react-router/src/Transitioner.tsx b/packages/react-router/src/Transitioner.tsx index 04e140acfcd..882778b3c6a 100644 --- a/packages/react-router/src/Transitioner.tsx +++ b/packages/react-router/src/Transitioner.tsx @@ -52,10 +52,10 @@ export function Transitioner() { _includeValidateSearch: true, }) - if ( - trimPathRight(router.latestLocation.href) !== - trimPathRight(nextLocation.href) - ) { + const latestPublicHref = trimPathRight(router.latestLocation.publicHref) + const nextPublicHref = trimPathRight(nextLocation.publicHref) + + if (latestPublicHref !== nextPublicHref) { router.commitLocation({ ...nextLocation, replace: true }) } diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index 3f1b59ea329..5fe37033cf8 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -1787,8 +1787,11 @@ export class RouterCore< return isEqual } + const latestPublicHref = this.latestLocation.publicHref ?? this.latestLocation.href + const nextPublicHref = next.publicHref ?? next.href + const isSameUrl = - trimPathRight(this.latestLocation.href) === trimPathRight(next.href) + trimPathRight(latestPublicHref) === trimPathRight(nextPublicHref) const previousCommitPromise = this.commitLocationPromise this.commitLocationPromise = createControlledPromise(() => { @@ -1945,11 +1948,14 @@ export class RouterCore< } } + const latestPublicHref = this.latestLocation.publicHref + const nextPublicHref = nextLocation.publicHref + if ( - trimPath(normalizeUrl(this.latestLocation.href)) !== - trimPath(normalizeUrl(nextLocation.href)) + trimPath(normalizeUrl(latestPublicHref)) !== + trimPath(normalizeUrl(nextPublicHref)) ) { - throw redirect({ href: nextLocation.href }) + throw redirect({ href: nextPublicHref }) } } diff --git a/packages/solid-router/src/Transitioner.tsx b/packages/solid-router/src/Transitioner.tsx index 2d602a2022c..6aa52ba6dd9 100644 --- a/packages/solid-router/src/Transitioner.tsx +++ b/packages/solid-router/src/Transitioner.tsx @@ -50,10 +50,10 @@ export function Transitioner() { _includeValidateSearch: true, }) - if ( - trimPathRight(router.latestLocation.href) !== - trimPathRight(nextLocation.href) - ) { + const latestPublicHref = trimPathRight(router.latestLocation.publicHref) + const nextPublicHref = trimPathRight(nextLocation.publicHref) + + if (latestPublicHref !== nextPublicHref) { router.commitLocation({ ...nextLocation, replace: true }) } From 977587d826f66a1185f206a80f240c3445a841e8 Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Wed, 1 Oct 2025 08:59:08 +0900 Subject: [PATCH 05/10] trigger CI From 7f764e827e63be666540246d5ade83933478e846 Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Thu, 2 Oct 2025 00:03:12 +0900 Subject: [PATCH 06/10] trigger CI From bcff760e8571421e36ded6244da97b02e76bd60e Mon Sep 17 00:00:00 2001 From: "autofix-ci[bot]" <114827586+autofix-ci[bot]@users.noreply.github.com> Date: Wed, 1 Oct 2025 15:04:12 +0000 Subject: [PATCH 07/10] ci: apply automated fixes --- packages/router-core/src/router.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index 5fe37033cf8..fc0d71c3747 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -1787,7 +1787,8 @@ export class RouterCore< return isEqual } - const latestPublicHref = this.latestLocation.publicHref ?? this.latestLocation.href + const latestPublicHref = + this.latestLocation.publicHref ?? this.latestLocation.href const nextPublicHref = next.publicHref ?? next.href const isSameUrl = From 92154413c0f14ea77186a1918669fb7a4dd4afc8 Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Thu, 2 Oct 2025 09:18:52 +0900 Subject: [PATCH 08/10] fix(router): revert the href value Signed-off-by: leesb971204 --- packages/router-core/src/router.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index fc0d71c3747..0bac9a627aa 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -1691,7 +1691,7 @@ export class RouterCore< return { publicHref: rewrittenUrl.pathname + rewrittenUrl.search + rewrittenUrl.hash, - href: rewrittenUrl.href.replace(rewrittenUrl.origin, ''), + href: fullPath, url: rewrittenUrl.href, pathname: nextPathname, search: nextSearch, From 918e51e8858a5d2f46684b2b1798fa0d6604ada8 Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Thu, 2 Oct 2025 09:31:59 +0900 Subject: [PATCH 09/10] trigger CI From a22766aeb88ec039f47441d4a19d69bd0239670f Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Thu, 2 Oct 2025 09:49:06 +0900 Subject: [PATCH 10/10] fix(router): revert handle server redirect by #5330 Signed-off-by: leesb971204 --- packages/router-core/src/router.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/router-core/src/router.ts b/packages/router-core/src/router.ts index 43edec186ce..8c49d4271f3 100644 --- a/packages/router-core/src/router.ts +++ b/packages/router-core/src/router.ts @@ -1949,14 +1949,11 @@ export class RouterCore< } } - const latestPublicHref = this.latestLocation.publicHref - const nextPublicHref = nextLocation.publicHref - if ( - trimPath(normalizeUrl(latestPublicHref)) !== - trimPath(normalizeUrl(nextPublicHref)) + trimPath(normalizeUrl(this.latestLocation.href)) !== + trimPath(normalizeUrl(nextLocation.href)) ) { - throw redirect({ href: nextPublicHref }) + throw redirect({ href: nextLocation.href }) } }