robisim74/qwik-speak

Showing 404 page in localized routing with lang param

Closed this issue · 3 comments

Suppose I have the following folder structure:

[...lang]
   about/index.tsx
   index.tsx

Visiting / and /about/ both works, but if I visit /pageThatDoesNotExist/ it still renders / since [...lang] catches all routes.
How can I display a 404 page in this case?

@samyung0 Routing is provided by Qwik City.

This library only provides helper methods for managing paths, and the solution with the optional language [...lang] is just an example to get you started.

That said, if you need to manage 404, you may want to consider at least two alternatives:

  • Make the language mandatory [lang], and create an index page to redirect based on the language
  • Validate the paths yourself, for example by accessing the routes of qwikCityPlan: import qwikCityPlan from '@qwik-city-plan'; and throw a 404 if the route doesn't exist

Hope this helps.

Hmm thanks for the advice. I am not sure what are the implications on SEO (if any) if I redirect / to for example /en-US/.
I ended up modifying qwik-city and added in optional param route matching and it works fine.

Ok, if you like and have time to do a pr to add an example of the solution to the documentation, you are welcome