Navigation
A navigation Key is needed to create navigation commands that change the URL. That includes pushUrl, replaceUrl, back, and forward.
useRouter
Usage
import React from 'react';
import useRouter from '@/hooks/navigation/useRouter';
function MyComponent() {
// Get the router object
const router = useRouter();
// Get value from query string (?postId=123) or route param (/:postId)
console.log(router.query.postId);
// Get current pathname
console.log(router.pathname);
// Navigate with with router.push()
return <button onClick={(e) => router.push("/about")}>About</button>;
}Last updated