Catch-all route catches unwanted files #16110
Replies: 4 comments 6 replies
|
You could check the |
|
Hi, I ran into the same issue. Is this a bug or wanted behaviour? I find it a bit weird that .png files are treated as pages. In Nuxt 2 if you request image it will always give back image (broken one with 404 error in case the assets does not exists). And in case of Nuxt 3 it will treat it as a page and serve error page. |
|
For a catch-all page I would treat this as an early-routing guard, not as a backend lookup failure. A For your Vercel const route = useRoute()
const path = route.path
if (
path.startsWith('/_nuxt/') ||
path.startsWith('/__nuxt') ||
/\/[^/]+\.[a-z0-9]{1,12}$/i.test(path)
) {
throw createError({
statusCode: 404,
statusMessage: 'Not Found',
})
}Then only call the e-commerce backend after that guard passes. I would keep this check as close as possible to the catch-all route or the server/API function that performs the lookup. If you put it in global middleware, make sure it does not accidentally block legitimate routes that happen to contain dots, for example usernames, slugs, or docs pages. The file-extension regex is a good default for asset-like paths, but the safest allow/deny rules depend on your URL scheme. For static files you own, prefer placing them under |
Uh oh!
There was an error while loading. Please reload this page.
Building a site that uses the [...slug].vue catch all route.
We use the parameters to call an api to get some data back. This part works great.
How ever we have some 3rd party that from time ends up making requests to non-existing assets eg: 'assets/dummy.png'
The [...slug] route will catch this and end up in unhandled errors.
Is there some way to exclude all urls containing a file ending from the [...slug] route. Or maybe some even better way of handling this scenario?
All reactions