Replies: 7 comments 30 replies
-
Are you doing static generation? If so |
Beta Was this translation helpful? Give feedback.
-
have same problem and here is my solution
|
Beta Was this translation helpful? Give feedback.
-
There is still no workaround on this? |
Beta Was this translation helpful? Give feedback.
-
I've found a solution. Surely, you can do it using Next.js' getStaticProps and getStaticPaths but it's a good practice to keep things closely tied to the JS core.
If you want to get the last element outside the useEffect() call the useRouter():
Since my project doesn't need additional pages being generated at build time this is enough. If this is not your case then it's probably better to use getStaticProps and getStaticPaths. |
Beta Was this translation helpful? Give feedback.
-
I found something:
And the code would be like: const router = useRouter();
useEffect(()=>{
if(!router.isReady) return;
// codes using router.query
}, [router.isReady]); |
Beta Was this translation helpful? Give feedback.
-
If you're yet to upgrade to v10.0.5 > this worked for me: const router = useRouter();
useEffect(() => {
if (Object.keys(router.query).length > 0) {
// code using router.query
}
}, [router.query]); |
Beta Was this translation helpful? Give feedback.
-
Anyone got a working solution for NextJS 13?? |
Beta Was this translation helpful? Give feedback.
-
I need to call an api on the basis of some query values but I am only able to get params when I use router.query within useEffect and not getting any query params.
Beta Was this translation helpful? Give feedback.
All reactions