withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.57k stars 2.47k forks source link

Dynamic Routes that starts with 404 redirects to 404 page rather than loads properly #11595

Open braden-w opened 3 months ago

braden-w commented 3 months ago

Astro Info

Astro                    v4.12.2
Node                     v22.4.1
System                   macOS (arm64)
Package Manager          pnpm
Output                   hybrid
Adapter                  none
Integrations             @astrojs/react
                         @astrojs/tailwind

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

In dynamic routes, any dynamic route that starts with "404", even if it is not an exact match like "4045", results in a 404 page.

If there is a /pages/todos/[id].astro file, visiting /todos/4045, /todos/404a, etc. gives 404 pages such as the following:

CleanShot 2024-08-01 at 17 37 08

What's the expected result?

If there is a /pages/todos/[id].astro file, visiting /todos/4045, /todos/404a, etc. should instead meet pass "4045" or "404a" as a param and load the corresponding todo.

Link to Minimal Reproducible Example

https://stackblitz.com/github/withastro/astro/tree/latest/examples/basics?file=src%2Fpages%2Findex.astro

Participation

agrofx1 commented 2 months ago

So, I examined source code and figured out that problem occurs here or here.

ematipico commented 2 months ago

I assigned the issue to you @braden-w

We should apply the same fix for 505 pages:

https://github.com/withastro/astro/blob/d532df1222273f9ef900abafc7aa4308235bb2ff/packages/astro/src/vite-plugin-astro-server/route.ts#L42-L45

https://github.com/withastro/astro/blob/d532df1222273f9ef900abafc7aa4308235bb2ff/packages/astro/src/i18n/index.ts#L25

thank you @agrofx1 for the help

ematipico commented 3 weeks ago

@braden-w any updates?

braden-w commented 3 weeks ago

@ematipico Just attempted my first PR at #12182 ! Let me know if it looks good. Thanks for the reminder

dwighthouse commented 3 weeks ago

@braden-w Your PR looks good to me after a cursory glance through it.

On a related note, do you happen to know what mechanism within the codebase is responsible for changing the output file paths from /404/index.html and /500/index.html to 404.html and 500.html respectively? That is, where is the specific exception code to treat these pages different from all other pages when deciding where to output the rendered files?

I've been trying to find a way to output these pages the way any other page is output, preferably with a configuration option for people who want their 404 and 500 pages to be at /404/ and /500/, respectively.