Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

double catch-all doesn't work (both [...slug].vue and a 404.vue) #14702

Closed
talaxasy opened this issue Aug 24, 2022 · 9 comments · Fixed by nuxt/framework#8809
Closed

double catch-all doesn't work (both [...slug].vue and a 404.vue) #14702

talaxasy opened this issue Aug 24, 2022 · 9 comments · Fixed by nuxt/framework#8809

Comments

@talaxasy
Copy link

Environment

  • Operating System: Linux
  • Node Version: v16.17.0
  • Nuxt Version: 3.0.0-rc.8
  • Package Manager: npm@8.11.0
  • Builder: vite
  • User Config: -
  • Runtime Modules: -
  • Build Modules: -

Reproduction

https://stackblitz.com/edit/nuxt-starter-87chgu?file=pages/[...slug].vue

Describe the bug

Catch-all routes don't work like in documentation - https://v3.nuxtjs.org/guide/directory-structure/pages#catch-all-route

Additional context

No response

Logs

No response

@talaxasy talaxasy changed the title Catch-all routes doesn't work Catch-all routes don't work Aug 24, 2022
@SebbeJohansson
Copy link

I can confirm that it doesnt work for me either.
https://stackblitz.com/edit/nuxt-starter-w3dcms?file=pages%2F404.vue,pages%2F[...slug].vue

@danielroe
Copy link
Member

The issue is that [...slug].vue and a 404.vue both produce catchall routes and the 'first' one will handle the request.

I'll look into this and see if there's a way we can improve the DX here, or add something to the docs to make this clearer.

https://v3.nuxtjs.org/guide/directory-structure/pages/#catch-all-route

@SebbeJohansson
Copy link

@danielroe

The issue is that [...slug].vue and a 404.vue both produce catchall routes and the 'first' one will handle the request.

So if I understand it correctly, the only option is to remove the 404.vue and make a custom solution for the 404?

@jonnyparris
Copy link

In case you were facing this issue while trying to use Nuxt Content like I was then you might also want to use the #not-found slot to render your custom 404 content instead of using 404 as a page.

@dixhuit
Copy link

dixhuit commented Oct 12, 2022

Just hit this myself. Why is this only priority 3? Catch-all routes are very common in CMS driven Nuxt sites, as are the need for 404 pages.

@danielroe
Copy link
Member

#14702

The issue isn't that catch-all routes don't work, but that adding two catch-all routes leads to unexpected results.

@danielroe danielroe changed the title Catch-all routes don't work double catch-all doesn't work (both [...slug].vue and a 404.vue) Oct 12, 2022
@dixhuit
Copy link

dixhuit commented Oct 12, 2022

The issue isn't that catch-all routes don't work, but that adding two catch-all routes leads to unexpected results.

I get that. That's also my point: having both a catch-all route and a 404 provision (another form of catch-all route) is very common, especially in CMS driven sites.

@manniL
Copy link
Member

manniL commented Oct 12, 2022

Instead of using a separate route, you could also render a 404.vue component in your [...slug].vue route when it doesn't match anything ☺️

@dixhuit
Copy link

dixhuit commented Oct 12, 2022

Instead of using a separate route, you could also render a 404.vue component in your [...slug].vue route when it doesn't match anything relaxed

That's exactly what I've had to do for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants