Problem with getStaticPaths and getStaticProps #15829
-
This might be the dumbest question on this forum, but I had to ask it. Maybe I am understanding this all wrong, but my goal is to make the dynamic routes work in an exported next js app. Based on what I understood from the docs, I have to declare all possible routes in The pages - pages/index.js
pages/product/[name].js
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Next.js would work fine in this scenario!
You'd want to remove // pages/product/[name].js
import { useRouter } from "next/router";
const Product = () => {
const r = useRouter();
const { name } = r.query;
if (!name) {
return (
<div>
<p>Loading...</p>
</div>
);
}
// TODO: data fetching
return (
<div>
<h1>Hi {name}</h1>
<p>Welcome to our product page for {name}!</p>
</div>
);
}; I'd highly suggest not using |
Beta Was this translation helpful? Give feedback.
Next.js would work fine in this scenario!
You'd want to remove
getStaticPaths
andgetStaticProps
in this case, as Next.js will automatically export the page statically. You'll then need to read the dynamic parameter fromuseRouter()
and fetch your data client-side.