Open MinJeung-Kim opened 1 year ago
src
// src/middleware.ts import { NextRequest, NextResponse } from "next/server";
// λͺ¨λ μμ²μ λν΄μ μ€ν. export function middleware(request: NextRequest) { console.log("λ―Έλ€μ¨μ΄κ° μ€νλκ³ μμ! 체ν¬μ€βοΈ "); if (request.nextUrl.pathname.startsWith("/products/1004")) { console.log("λ―Έλ€μ¨μ΄ - κ²½λ‘λ₯Ό 리λ€μ΄λ ν ν¨! "); return NextResponse.redirect(new URL("/products", request.url)); } }
// νΉμ κ²½λ‘μμλ§ μ€ν. export const config = { // /products/μ΄ν λͺ¨λ κ²½λ‘ matcher: ["/products/:path*"], };
![chrome_W43itZSjSj](https://github.com/MinJeung-Kim/NextJS-v13--Study/assets/79193369/f6b7b6df-7354-4eef-9e02-671ac97bbe61)
πͺMiddleware
src
μ΅μμ ν΄λ λλ νλ‘μ νΈ μ΅μμ ν΄μ μμ±.// λͺ¨λ μμ²μ λν΄μ μ€ν. export function middleware(request: NextRequest) { console.log("λ―Έλ€μ¨μ΄κ° μ€νλκ³ μμ! 체ν¬μ€βοΈ "); if (request.nextUrl.pathname.startsWith("/products/1004")) { console.log("λ―Έλ€μ¨μ΄ - κ²½λ‘λ₯Ό 리λ€μ΄λ ν ν¨! "); return NextResponse.redirect(new URL("/products", request.url)); } }
// νΉμ κ²½λ‘μμλ§ μ€ν. export const config = { // /products/μ΄ν λͺ¨λ κ²½λ‘ matcher: ["/products/:path*"], };