'404 page not working on Nextjs Static Generated File

Im having trouble to show 404 custom page i made when i generate static generated file (next build && next export)

When im navigation to non existing page ("/<any-non-existing"), it always redirects to homepage ("/"). My expectation is that it will automatically redirect to ("/404").

However, if im manually navigation to ("/404") page, the page works perfectly fine.

Deployed to S3 with Cloudfront Enabled next.config.js { trailingSlash: true }



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source