Created
December 4, 2022 19:51
-
-
Save KrisKnez/958268ccc9c653cd6615b4ba1decaeb4 to your computer and use it in GitHub Desktop.
Next.JS Link while keeping query / url parameters
This file contains hidden or 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 React, { ReactNode } from 'react' | |
| // Next | |
| import Link from 'next/link' | |
| import { useRouter } from 'next/router' | |
| const SomeComponent = () => { | |
| const router = useRouter(); | |
| return ( | |
| <div> | |
| <Link href={{ | |
| pathname: 'signup', | |
| query: router?.query | |
| }}> | |
| Click me! | |
| </Link> | |
| </div> | |
| ) | |
| } | |
| export default SomeComponent |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
router.query will not be defined in the initial render until router.isReady is equal to true.