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
Assets path are conflicting with routing #9379
Comments
Are you using
One quick and easy solution is to check If you need more control, you can implement your own express server and set up an |
Thanks for your help. How to do this:
|
I think what he means is that in your loader for the export async function loader({ request, params }: LoaderFunctionArgs) {
validateLangParam(params.lang)
// ... continue
}
function validateLangParam(lang: string) {
if (lang === 'images') {
throw new Response('Not Found', { status: 404 })
}
// or you can do
if (lang && !(['en', 'fr', 'es', 'de'].includes(lang))) {
throw new Response('Not Found', { status: 404 })
}
} |
Thanks, but I definitely don't want to do this in every loader. Also, hit a new problem. I have these routes:
As the lang is optional, now this path Is there any way to do something like this:
|
Good job |
Reproduction
It hard to reproduce as it happens infrequently, maybe several times a day, but I'll explain the issue in very detail. I cannot reproduce it locally. But it is reported by Sentry a few times a day.
This is my route:
app/routes/($lang).products.$id
.And this is my image path:
/images/products/abc1-s@1x.webp
. The images for the products are located inpublic/images/products/...
.And this is the error from Sentry:
The actual error from my
($lang).products.$id.tsx
component isError Invariant failed.
, because it cannot find a product with that ID.Why the router matches a path for my assets in the public directory? I understand that this regex
$param.products.$param
matches this URL/images/products/abc
, but it shouldn't. I am asking for an image here.Please, help! This happens 300 times by now and users cannot see the images. But when they refresh the page - it works.
System Info
Used Package Manager
yarn
Expected Behavior
I expect that assets paths won't conflict with routing.
Actual Behavior
Assets paths conflicting with routing.
The text was updated successfully, but these errors were encountered: