Confusion about error.tsx vs global-error.tsx #68048
Unanswered
g1na1011
asked this question in
App Router
Replies: 1 comment 1 reply
-
Hi @g1na1011 From what I read from here and here, you need both: "An error.js boundary will not handle errors thrown in a layout.js component in the same segment because the error boundary is nested inside that layouts component.
"The root app/error.js boundary does not catch errors thrown in the root app/layout.js or app/template.js component. To specifically handle errors in these root components, use a variation of error.js called app/global-error.js located in the root app directory." Which I understand as: global-error.js isn't used when error.js should be but isn't there. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there! We are using Next.js App Router to develop a new architecture for our app. We are starting off with a pure static page that is fairly simple, no nested routes required. Can you help me explain why or when we would want both an
error.tsx
and aglobal-error.tsx
page? Our error pages would have the same design, so we thought we can removeerror.tsx
and just keepglobal-error.tsx
. To our surprise, using justglobal-error.tsx
renders a blank white page when we throw a 500. Renaming that page back toerror.tsx
renders the expected page. Should we have both even though the designs are the same and we do not have a component-based error page?thank you for your help!
Beta Was this translation helpful? Give feedback.
All reactions