From 6cc330b0066605149810c777495eaa8858748f9b Mon Sep 17 00:00:00 2001 From: Thomas ACCHIARDO Date: Tue, 12 Mar 2024 08:45:12 +0100 Subject: [PATCH] (fix) routers - update url search params according to validate search --- packages/react-router/src/RouterProvider.tsx | 11 +++++++++++ packages/react-router/src/router.ts | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) 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 f6da487e765..fe3ee84dae4 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)