Skip to content

Commit

Permalink
fix: Support for useQueryState in dynamic routes
Browse files Browse the repository at this point in the history
  • Loading branch information
MRobertEvers authored and franky47 committed Oct 15, 2020
1 parent 1e94627 commit 4c44f9c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,13 @@ export function useQueryState<T = string>(
// Don't leave value-less keys hanging
query.delete(key)
}

// Remove fragment and query from asPath
// 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: router.pathname,
pathname: asPath,
hash: window.location.hash,
search: query.toString()
})
Expand Down

0 comments on commit 4c44f9c

Please sign in to comment.