I have a next.js app with app directory
.
├── app/
│ └── (public)/
│ ├── path1/
│ │ └── page.tsx
│ └── path2/
│ └── page.tsx
├── layout.tsx
└── page.tsx
I want to /path2
return 404
status (not a redirect)
export async function getStaticProps() {
return {
notFound: true, // triggers 404
};
}
export default function Path2Page() {
return (
<></>
);
}
And Error: × "getStaticProps" is not supported in app/. Read more:
My solution atm is set status in middleware, but is there another method?
export function middleware(request: NextRequest) {
if (request.nextUrl.pathname === '/path2') {
return NextResponse.next({status: 404});
}
return NextResponse.next();
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744961494a4603411.html
评论列表(0条)