notFound function
notFound 함수는 새로운 NotFoundError 객체를 반환하며, 이 객체는 라우트의 beforeLoad 또는 loader 콜백과 같은 위치에서 반환하거나 던질 수 있어 notFoundComponent를 트리거합니다.
notFound options
notFound 함수는 not-found 에러 객체를 생성하기 위한 단일 선택적 인수 options를 받습니다.
- 타입:
Partial<NotFoundError> - 선택 사항
notFound returns
options객체에서throw속성이true인 경우, 함수 호출 내에서NotFoundError객체가 던져집니다.options객체에서throw속성이false | undefined인 경우,NotFoundError객체가 반환됩니다.
Examples
import { notFound, createFileRoute } from "@tanstack/react-router";
const Route = new createFileRoute("/posts/$postId")({
// not-found 객체를 던지기
loader: ({ context: { post } }) => {
if (!post) {
throw notFound();
}
},
// 전체 페이지에 not-found를 표시하고 싶은 경우
loader: ({ context: { team } }) => {
if (!team) {
throw notFound({ global: true });
}
},
// ... 기타 라우트 옵션
});