Elderjs / elderjs

Elder.js is an opinionated static site generator and web framework for Svelte built with SEO in mind.
https://elderguide.com/tech/elderjs/
MIT License
2.12k stars 53 forks source link

404 Page #80

Closed flauc closed 4 years ago

flauc commented 4 years ago

How do you add a 404 page? I'm really sorry if I'm missing something obvious.

flauc commented 4 years ago

I was, just adding a 404 route works fine. I just needed to specify the template in the route.js file because it didn't get detected automatically.

svandegar commented 3 years ago

Hi @flauc , would you mind explaining your solution in detail?

I feel kind of dumb, after 3 hours of trying to set my 404 page without success.

flauc commented 3 years ago

Hi @svandegar, this is my setup in route.js

module.exports = {
  all: () => [{ slug: '404' }],
  template: '404.svelte',
  permalink: ({ request }) => `/${request.slug}`,
};

Basically just adding template is what fixed it for me.

image

svandegar commented 3 years ago

Thank you!

I copy-pasted your exact route.js content and still, navigating to a non-existing page like localhost:3000/foo does not show my 404.

The only way I can see my 404 page is by navigating specifically to localhost:3000/404

I guess I must be missing some config somewhere else to redirect 404 requests to this page but no idea where to look.

nickreese commented 3 years ago

@flauc look at the polka definition for 404. https://github.com/lukeed/polka#optionsonnomatch

flauc commented 3 years ago

Sorry @svandegar I'm now seeing that it does indeed not work locally (which is when polka is involved), however it does work as expected on live https://glycanage.com/some-bad-link.

Thank you @nickreese

svandegar commented 3 years ago

Thanks for the doc but my 404 is still not appearing, even on prod: https://estimer.com/some-bad-link When I check my public folder, I see that the 404.html is missing at the root. I just have a ./404/index.html but this is not where my hosting (Firebase) is looking for the 404 page.

Is there a way to make it work, other than editing the public folder content manually after each build?

nickreese commented 3 years ago

Add a function on the requestComplete hook to write the 404.html file. That is your best bet.

svandegar commented 3 years ago

Gonna try that. Thanks for your help!