React navigation #76324
Answered
by
talhajavedcom
MuhammadAzeemShoukat077
asked this question in
App Router
React navigation
#76324
-
|
Can we use React Router DOM in Next.js to stop navigation API calls? |
Beta Was this translation helpful? Give feedback.
Answered by
talhajavedcom
Feb 21, 2025
Replies: 1 comment
-
Noit's not recommended to use React Router DOM in Next.js. Use Next.js useRouter and AbortController to stop API calls during navigation. Stop API Calls on Navigation in Next.js
Code Exampleimport { useEffect } from "react";
import { useRouter } from "next/router";
export default function Page() {
const router = useRouter();
useEffect(() => {
const controller = new AbortController();
const handleRouteChange = () => controller.abort();
router.events.on("routeChangeStart", handleRouteChange);
return () => router.events.off("routeChangeStart", handleRouteChange);
}, [router]);
return <div>Page Content</div>;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
MuhammadAzeemShoukat077
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No
it's not recommended to use React Router DOM in Next.js. Use Next.js useRouter and AbortController to stop API calls during navigation.
Stop API Calls on Navigation in Next.js
Code Example