From 23be5f9d773baf950be6ddb2271f55ded775541f Mon Sep 17 00:00:00 2001 From: leesb971204 Date: Wed, 24 Sep 2025 13:59:34 +0900 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] trigger CI