I have a NextJS middleware where I need to check if a category exists. If not, go to a 404 page.
The directory looks like this
pages/
├──[category_code].jsx
└── ...(other pages)
middleware.jsx
The middleware is being executed but how do I match this path in the matcher config?
Here’s my middlware
import { NextResponse } from "next/server";
export async function middleware(request) {
// this is executed
}
// I need this middleware to target [category_code].jsx
export const config = {
matcher: "/pages/:path",
};
I need this middleware to target [category_code].jsx but it doesn’t.
Ive tried
/:path
/:path*
/:category_code
/[category_code]
What should I do?