I have a link: appBaseUrl/edit/:userId
I want it to be transited by next/router like following:
router.push(`appBaseUrl/edit/${userId}`)
and in the getServerSideProps function is like following:
export const getServerSideProps: GetServerSideProps = async ({props}) => {
const parsedProps = parseProps(props);
const fetchedValues = await fetchFunction(params).data;
// ... another 10 fetch queries
if (!isValueValid(fetchedValues)) {return {notFound: true}}
return {
props: {
...parsedProps,
fetchedValues,
// ... other fetchedValues
}
}
}
No condition in the component function btw.
now the issue is,
if i visit the page directly by url with invalid userId, or by window.location.replace
, the 404 show up as expected,
but when using next.router transition, it result in runtime error because react try to render page with undefined props).
Adding customized 404 page would not help.
I have not found working solutions so far.
Any help would be appreciated