mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
### What? Throwing a `notFound()` error inside of a segment that has an error boundary will cause it to be handled by the segment's error boundary rather than a parent not-found boundary. ### Why? We assume anything that hits an `ErrorBoundary` is an actual error, but this should not be the case when the caught error is one that is handled by Next.js. ### How? This checks if the caught error is one that is expected to be handled someplace else. Closes NEXT-2080 [slack x-ref](https://vercel.slack.com/archives/C03S8ED1DKM/p1705003189392509?thread_ts=1704868742.169129&cid=C03S8ED1DKM)
19 lines
351 B
JavaScript
19 lines
351 B
JavaScript
'use client'
|
|
import { notFound } from 'next/navigation'
|
|
import React from 'react'
|
|
export default function Page() {
|
|
const [shouldError, setShouldError] = React.useState(false)
|
|
if (shouldError) {
|
|
notFound()
|
|
}
|
|
return (
|
|
<button
|
|
onClick={() => {
|
|
setShouldError(true)
|
|
}}
|
|
>
|
|
Trigger Not Found
|
|
</button>
|
|
)
|
|
}
|