import { useRouter } from 'next/router'
function ActiveLink({ children, href }) {
const router = useRouter()
const style = {
marginRight: 10,
color: router.asPath === href ? 'red' : 'black',
}
const handleClick = (e) => {
e.preventDefault()
router.push(href)
}
return (
<a href={href} onClick={handleClick} style={style}>
{children}
</a>
)
}
export default ActiveLink
{}isReady: boolean - Whether the router fields are updated client-side and ready for use. Should only be used inside of useEffect methods and not for conditionally rendering on the server. See related docs for use case with automatically statically optimized pages
const router = useRouter();
useEffect(())=>{
if(router.isReady){ // router가 준비 되었을때
console.log(router.query)
}
}, [router.query])
{ } 추가로 isReady : falseisReady : true 가 된다.<aside> 💡 router 객체에는 여러가지 있다.
</aside>
router.push(url, as, { scroll : true})