I have a website (let’s call it example.com
) built with Next.js, statically exported. When I type in a wrong address in the browser (i.e. https://example.com/wrong-addr
), it redirects to /404.html
, a default fallback file provided by Next.js. Here is what I think happening:
-
The server checks whether
/wrong-addr/index.html
exists. No, it
doesn’t. -
The server checks whether
/wrong-addr.html
exists. No, it doesn’t. -
The server gets lost and the browser displays browser-default 404 page.
But, instead of #3, Next.js somehow magically shows its own /404.html
file. How can it do that? It seems that there was no chance for the server to run any js file or anything as it couldn’t hit any real html file. No .htaccess
or similar config exists either. What am I missing here?
I tested with static files that I manually created and they couldn’t hit /404.html
but returned browser 404 as expected in #3.
(Please note that I’m not asking about Next.js configurations or enabling routers.)