env:{
baseUrl: env.NEXT_PUBLIC_API_BASE_URL
}
trailingSlash: true
import { NextResponse } from 'next/server';
export function middleware(req) {
const { pathname } = req.nextUrl;
const basePath = '/my-app'; // 설정한 basePath
// basePath로 시작하고 끝에 슬래시가 없는 경우
if (pathname === basePath || pathname.startsWith(`${basePath}/`)) {
if (pathname === basePath) {
// /my-app -> /my-app/로 리디렉션
return NextResponse.redirect(new URL(`${basePath}/`, req.url));
}
// 다른 경로(예: /my-app/about)는 그대로 유지
return NextResponse.next();
}
// basePath와 무관한 경로는 기본 처리
return NextResponse.next();
}
z
'code잇(리액트) > 팁' 카테고리의 다른 글
IT References Blog Git (0) | 2024.11.26 |
---|---|
리액트플로우 업데이트 (0) | 2024.10.25 |
post react 참조 (0) | 2024.10.23 |
VSCode 기능 소개 (0) | 2023.08.27 |