Next.js Discord

Discord Forum

How to trigger the not found page manually

Answered
Asian paper wasp posted this in #help-forum
Open in Discord
Asian paper waspOP
I have dynamic routing in my application. But there are only 4 possible routes. If the route is not in the possible routes, I want to trigger the not-found page.
Answered by Asian paper wasp
Ok I found it
import { notFound } from "next/navigation"

export default function Page() {
    if (something) {
        notFound()
    }
}
View full answer

2 Replies

Asian paper waspOP
Ok I found it
import { notFound } from "next/navigation"

export default function Page() {
    if (something) {
        notFound()
    }
}
Answer