I have a [pid].js file in my Next.js project. I also wanted to implement a custom 404 page but here is the problem: I put 404.js file inside /pages directory. If I delete my [pid].js file, 404 page works just fine. But, if I keep my [pid].js file, the first request goes into pids, and since the url does not match any of the pages defined in pids, I get an error. Should I explicitly return my 404 component from pids? Is this a good practice?
Here is the code (which does not redirect to 404 page right now):
[pid].js
const Pid = ({ url, props }) => {
const getPages = () => {
let component = null;
switch (url) {
case 'checkout':
component = <CheckoutPage {...props} />;
break;
//other switch cases...
default:
//should I return my 404 component here?
component = <DefaultPage {...props} />;
}
return component;
};
return getPages();
};
export async function getServerSideProps(context) {
const res = await getReq(`/getUrl`, 'content', context);
switch (res.url) {
case 'checkout': {
return {
props: {
url: res.url,
props: {
... //my other props
},
},
};
}
default:
return {
props: null,
};
}
}
Pid.propTypes = {
url: PropTypes.string.isRequired,
};
export default Pid;