Skip to content

Instantly share code, notes, and snippets.

@Uvacoder
Forked from jordantwells42/routing.ts
Created June 17, 2024 00:45
Show Gist options
  • Select an option

  • Save Uvacoder/4397f2d1dcdbd77385b62141b00f3402 to your computer and use it in GitHub Desktop.

Select an option

Save Uvacoder/4397f2d1dcdbd77385b62141b00f3402 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