Skip to content

Instantly share code, notes, and snippets.

@jordantwells42
Created August 8, 2022 04:49
Show Gist options
  • Select an option

  • Save jordantwells42/0f96c7c56045d4823c6f8a4c283dba28 to your computer and use it in GitHub Desktop.

Select an option

Save jordantwells42/0f96c7c56045d4823c6f8a4c283dba28 to your computer and use it in GitHub Desktop.
import { useEffect } from 'react'
import { useRouter } from 'next/router'
// Current URL is '/'
function Page() {
const router = useRouter()
useEffect(() => {
// Always do navigations after the first render
router.push('/?counter=10', undefined, { shallow: true, scroll: false })
}, [])
useEffect(() => {
// The counter changed!
}, [router.query.counter])
}
export default Page
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment