-
Notifications
You must be signed in to change notification settings - Fork 67
Unknown routes should render 404.html #2
Comments
Hi @gamliela, thank you for opening this issue and for sharing solutions of your own! I will look into it this week and get back to you soon. I'd be quite interested to hear how you ended up dealing with it after all: By copying the PS: Apologies for taking so long to get back. Somehow it totally slipped my attention. |
No worries :) Yes, I simply copy the |
Hmmm, very true. I like the idea! Two considerations:
|
Good points!
Probably not overriding - what is the existing behaviour (for example when generating the
I am not sure that 404 page can be dynamic, it is a safe fallback mechanism that is supplied by Nelify (not next.js) when no other route could be found. As Netlify not aware to dynamic content, I'm not sure you can make this page dynamic. I tried catch-all rule at the end of the routes file, but I don't remember now if it ever worked for me... |
Hey @gamliela, This is finally being fixed in the upcoming I've already written the code and tests; it works wonderfully. There are a few more things I want to look into before releasing v2, but I'm getting very close! Finn 🙂 PS:
You were totally right on this. I was confusing it with the |
Thanks for the update! great news :) I've tested
My test project is at https://github.com/gamliela/playground-auth/tree/next-on-netlify-v2 Thanks for the awesome work! looking forward seeing the final version :) |
When we copy the pre-rendered pages to `out/`, we do a check to make sure that the file does not already exist. This is to make sure that we don't silently overwrite one of the files copied from `public/`, for example. But for `index.js` files, Netlify always creates two page entries, one routing to `/` and one routing to `/index`. So in this case, the first copying of `index.js` to `out/` goes fine. The second copying fails because `index.js` already exists. We fix this by first filtering our list of pages for unique pages and then performing the copy operation. Fixes: #2 (comment)
Hey @gamliela, Wow, thanks for checking it out so quickly and looking for issues!
Again, thanks for being so quick to take a look! 🙌 You definitely caught a major issue there! Keep up the search for more 😁 I am going to look into |
I'll continue playing with it and let you know if I find anything else. Thanks! |
- **Breaking: You must change your `netlify.toml` configuration for next-on-netlify v2.0.0.** Please look at the README for the latest configuration. `next-on-netlify` now builds pre-rendered pages and static assets in `out_publish`. Netlify Functions for SSR pages are built to `out_functions`. - Add support for `getStaticProps` (#7) - Add support for `getStaticPaths` with and without fallback (#7) - Add support for `getServerSideProps` (#7) - Query string parameters are now correctly passed to Next Pages and API endpoints (#9) - Response headers are now correctly set (#9) - When a user encounters a 404, `next-on-netlify` now display the NextJS 404 page rather than Netlify's default 404 page. You can customize the NextJS 404 page. (#2) - Every page with server-side rendering is now converted to a stand-alone Netlify Function. Previously, all SSR pages were bundled in a single Netlify Function. - `next-on-netlify` now prints out which pages are being converted to Netlify Functions for SSR, which pages are served as pre-rendered HTML, and the redirects that are being generated. - Adding custom redirects via a `_redirects` file in the project root is no longer supported. Let me know if you want this back. Or define your redirects in `netlify.toml`.
Hey @gamliela,
Thank you for your bug-hunting and for brainstorming the best way to tackle the 404-page! Unfortunately, I had to change the configuration again. So you'll need to make some changes to your # netlify.toml
[build]
command = "npm run build"
functions = "out_functions"
publish = "out_publish"
[dev]
functions = "out_functions"
publish = "out_publish"
framework = "#static" And you will want to adjust your # .gitignore
# Files generated by next-on-netlify command
/out_publish/
/out_functions/
/404.html Let me know if you run into any trouble. I closed this issue for now, but let's reopen it at any time if necessary! I've made a note to file an issue with If you build something awesome, let me know! I'd love to feature some real-world projects in the README. Happy hacking! 🔥 |
I know it's been a while, but I wanted to share a quick update: I finally wrote a fix for |
Unbelievable! great news, thank you very much :) |
Hi,
Cool project! I was looking for something similar for quite long, and your solution seems to work pretty well!
The current implementation doesn't support rendering of the
404.html
file, if an unknown URL is requested. For example, try this link:https://next-on.netlify.com/some-non-existing-url
- it should actually render_next/pages/404.html
file.A quick fix that I've found for this problem is to simply copy the
404.html
file topublic
in a post-build step. Something likecp public/_next/pages/404.html public
. The reason is that Netlify are expecting to find this file exactly on this place. But I wonder if that's the right solution, or if there are better ways. Another approach that I've tried was to add/* /_next/pages/404.html 404
at the end of_redirects
file, but it didn't work very well withnetlify-dev
.Would love to hear your thoughts. Thanks :)
The text was updated successfully, but these errors were encountered: