How to enable shallow routing

Answer

To enable shallow routing, set the shallow option to true. Consider the following example:-


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 })
}, [])

useEffect(() => {
// The counter changed!
}, [router.query.counter])
}

export default Page

All routing Questions

Ask your interview questions on routing

Write Your comment or Questions if you want the answers on routing from routing Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---