Skip to content

Instantly share code, notes, and snippets.

@KrisKnez
Created December 4, 2022 19:51
Show Gist options
  • Select an option

  • Save KrisKnez/958268ccc9c653cd6615b4ba1decaeb4 to your computer and use it in GitHub Desktop.

Select an option

Save KrisKnez/958268ccc9c653cd6615b4ba1decaeb4 to your computer and use it in GitHub Desktop.
Next.JS Link while keeping query / url parameters
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
@KrisKnez
Copy link
Author

KrisKnez commented Dec 4, 2022

router.query will not be defined in the initial render until router.isReady is equal to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment