Shallow routing allows you to change the URL without running data fetching methods again.
https://github.com/vercel/next.js/discussions/48110
npm install next-router-shallow
yarn add next-router-shallow
pnpm add next-router-shallow
import { useRouter } from "next/navigation";
import "next-router-shallow";
export default function MyComponent() {
const router = useRouter();
const onClick = () => {
router.shallow("/blog?search=shallow");
};
...
}
[!IMPORTANT]
This import must be made in any file that uses therouter.shallow()
method.