Hey folks, I get a flash of 'Not found' (that is the default case i've written as shown below) when refreshing browser a dynamic route.
As you can see, I am getting the id during component rendering, so i expect id to be available before the return statement.
for eg: /section/homes can be the dynamic route
const router = useRouter();
const id = router.query.id;
const getSection = (id) => {
switch (id) {
case "homes":
return <Homes />;
case "grounds":
return <Grounds />;
case "comforts":
return <Comforts />;
case "location":
return <Location />;
case "legacy":
return <Legacy />;
default:
return <div>Not found</div>;
}
};
return <div>{getSection(id)}</div>;
}
export default Section;
How can I prevent this?