From 84e70bb9e3d792d0188b3f586e64b8ce854113df Mon Sep 17 00:00:00 2001 From: Matthew Evers Date: Sat, 29 Aug 2020 13:37:34 -0500 Subject: [PATCH] fix: do not cause SSR in dynamic paths --- .gitignore | 1 + src/index.ts | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index efd8441f..c18c5746 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ coverage/ yarn-error.log # Docker containers with persistance .volumes/ +package-lock.json \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index 258ea862..46520456 100644 --- a/src/index.ts +++ b/src/index.ts @@ -83,11 +83,19 @@ export function useQueryState( // router.pathname includes dynamic route keys, rather than the route itself, // e.g. /views/[view] rather than /views/my-view const [asPath] = router.asPath.split(/\?|#/, 1) - updateUrl?.call(router, { - pathname: asPath, - hash: window.location.hash, - search: query.toString() - }) + updateUrl?.call( + router, + { + pathname: router.pathname, + hash: window.location.hash, + search: query.toString() + }, + { + pathname: asPath, + hash: window.location.hash, + search: query.toString() + } + ) }, [key, updateUrl] )