export async function middleware(request:NextRequest) {
...
if (request.nextUrl.pathname.startsWith("/admin)) {
return NextResponse.redirect("/admin/notification")
}
}
...
...
export const config = {
matcher: [
"/((?!api|_next/static|_next/image|favicon.ico|main/youtube.mp4|asset).*)",
"/admin/:path*",
],
};

에러 발생 원인
- 리다이렉트 루프가 발생했기 때문에 해당 에러가 출력된것
- 리다이렉트가 계속 발생해서 브라우저나 서버가 요청을 중단시키는 경우이다.
- 리다이렉트 시킬 대상 경로인 "/admin/notification"도 마찬가지로 startsWith("/admin") 조건에 충족되기 때문에 루프에 빠지게 되는것이다.
해결
if (request.nextUrl.pathname === "/admin") {
return NextResponse.redirect("/admin/notification")
}