[英]Next JS Images after next build gives 404 images
默认的 URL 结构是 http://localhost:5000/_next/image?url="someURL"。
我希望 URL 像http://localhost:5000/demo/_next/image?url="someURL"。
这可以通过
// next.config.js
images: {
domains: ['example.domain.com'],
path: `/demo/_next/image`
},
在这里,找不到目录指向的_next/image 。
在此之后,所有的图像都给 404。我需要在下一个 js 中解决这个问题。
您是否尝试过创建一个中间件来将这些路由重写到正确的位置?
类似于: pages/_middleware.ts
的内容:
import { NextRequest, NextResponse } from 'next/server';
export function middleware(req: NextRequest): NextResponse {
if (req.nextUrl.href.includes('/demo/_next/image'))
return NextResponse.rewrite(
req.nextUrl.href.replace('/demo/_next/image', '/_next/image'),
);
return null;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.