Created
January 3, 2025 15:38
-
-
Save justgeek/9d7d9e04043e82de84f1ba2cd37d29b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useRouter, useSearchParams } from 'next/navigation'; | |
export function useRouterWithQuery() { | |
const router = useRouter(); | |
const searchParams = useSearchParams(); | |
const query = searchParams?.size ? `?${searchParams}` : ''; | |
const replaceWithQuery = (url: string) => router.replace(`${url}${query}`); | |
const pushWithQuery = (url: string) => router.push(`${url}${query}`); | |
return { router, replaceWithQuery, pushWithQuery }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment