diff --git a/packages/react-router/src/RouterProvider.tsx b/packages/react-router/src/RouterProvider.tsx index 7ea3c4f017e..41442d67b7f 100644 --- a/packages/react-router/src/RouterProvider.tsx +++ b/packages/react-router/src/RouterProvider.tsx @@ -142,6 +142,17 @@ function Transitioner() { } }) + const nextLocation = router.buildLocation({ + search: true, + params: true, + hash: true, + state: true, + }); + + if (routerState.location.href !== nextLocation.href) { + router.commitLocation({ ...nextLocation, replace: true }); + } + return () => { unsub() } diff --git a/packages/react-router/src/router.ts b/packages/react-router/src/router.ts index 9e85a2c7322..ce5f71186ab 100644 --- a/packages/react-router/src/router.ts +++ b/packages/react-router/src/router.ts @@ -873,7 +873,7 @@ export class Router< ? prevParams : { ...prevParams, ...functionalUpdate(dest.params!, prevParams) } - if (nextParams) { + if (Object.keys(nextParams).length > 0) { matches ?.map((d) => this.looseRoutesById[d.routeId]!.options.stringifyParams) .filter(Boolean)