Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
23be5f9
fix(router-core): ensure href proterty uses rewritten URL in buildLoc…
leesb971204 Sep 24, 2025
593cb78
fix(router-core): rewrite examples in RouterOptions for improved clarity
leesb971204 Sep 24, 2025
508303a
Merge remote-tracking branch 'upstream/main' into fix/buildlocation-h…
leesb971204 Sep 25, 2025
2b831cf
test(react-router): add tests for browser url includes basepath on ro…
leesb971204 Sep 26, 2025
a9dbeb7
Merge remote-tracking branch 'upstream/main' into fix/buildlocation-h…
leesb971204 Sep 26, 2025
b9a4ce3
Merge remote-tracking branch 'upstream/main' into fix/buildlocation-h…
leesb971204 Sep 29, 2025
e900a66
Merge branch 'main' into fix/buildlocation-href-rewrite
leesb971204 Sep 30, 2025
a161948
fix(router): use publicHref for URL comparisons in Transitioner and r…
leesb971204 Sep 30, 2025
977587d
trigger CI
leesb971204 Sep 30, 2025
7f764e8
trigger CI
leesb971204 Oct 1, 2025
bcff760
ci: apply automated fixes
autofix-ci[bot] Oct 1, 2025
9215441
fix(router): revert the href value
leesb971204 Oct 2, 2025
8ad0f67
Merge branch 'main' into fix/buildlocation-href-rewrite
leesb971204 Oct 2, 2025
918e51e
trigger CI
leesb971204 Oct 2, 2025
a22766a
fix(router): revert handle server redirect by #5330
leesb971204 Oct 2, 2025
5f52ff8
test(react-router): update router configuration to use basepath direc…
leesb971204 Oct 7, 2025
710f5cc
fix(react-router): handle cross-origin navigation in Transitioner com…
leesb971204 Oct 10, 2025
e8757e3
Merge branch 'main' into fix/buildlocation-href-rewrite
leesb971204 Oct 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions packages/react-router/src/Transitioner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,20 @@ 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) {
Comment on lines -55 to +58
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

publicHref carries rewrite/basePath changes that should reflect in the browser URL

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the case when the rewrite changes the origin?
we would need to do a hard navigation here i think

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we can get this solved, we can merge this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about the case when the rewrite changes the origin? we would need to do a hard navigation here i think

Sorry for the late reply — I was on vacation.
Are there any cases where the origin can be changed through basepath or rewrite?
I think a bit more explanation would be helpful.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes you can for example map a path segment to a subdomain via a rewrite.

see this test for example

it('should handle subdomain to path rewriting with input', async () => {

const latestOrigin = new URL(router.latestLocation.url).origin
const nextOrigin = new URL(nextLocation.url).origin

if (latestOrigin !== nextOrigin) {
if (typeof window !== 'undefined') {
window.location.href = nextLocation.url
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more appropriate to use router.navigate({ href: nextLocation.url })?

Copy link
Contributor

@schiller-manuel schiller-manuel Oct 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could just call router.navigate() in any case (so regardless whether origin changed or not)

however, router.navigate() needs to be made origin aware (it currently isnt)

}
return
}

router.commitLocation({ ...nextLocation, replace: true })
}

Expand Down
66 changes: 66 additions & 0 deletions packages/react-router/tests/router.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,72 @@ describe('basepath', () => {
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: () => <Outlet />,
})

const indexRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/',
component: () => <div data-testid="home">Home</div>,
})

const routeTree = rootRoute.addChildren([indexRoute])

const history = createMemoryHistory({
initialEntries: ['/my-app/'],
})

const router = createRouter({
routeTree,
history,
basepath: '/my-app',
})

render(<RouterProvider router={router} />)

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: () => <Outlet />,
})

const indexRoute = createRoute({
getParentRoute: () => rootRoute,
path: '/',
component: () => <div data-testid="home">Home</div>,
})

const routeTree = rootRoute.addChildren([indexRoute])

const history = createMemoryHistory({
initialEntries: ['/my-app/'],
})

const router = createRouter({
routeTree,
history,
basepath: '/my-app',
})

render(<RouterProvider router={router} />)

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: () => <Outlet />,
Expand Down
6 changes: 5 additions & 1 deletion packages/router-core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1804,8 +1804,12 @@ 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<void>(() => {
Expand Down
8 changes: 4 additions & 4 deletions packages/solid-router/src/Transitioner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}

Expand Down
Loading