_error.page.js
The page _error.page.js
is rendered when:
404 Page Not Found
)..page.js
/ .page.server.js
/ .page.route.js
) throws an error (500 Internal Server Error
).throw RenderErrorPage()
.For 1.
and 3.
, vite-plugin-ssr
automatically sets the following:
pageContext.is404 === true
pageContext.pageProps.is404 === true
We can
throw RenderErrorPage({ pageContext: { is404: false }})
to havepageContext.is404 === false
as well aspageContext.pageProps.is404 === false
.
For 2.
:
pageContext.is404 === false
pageContext.pageProps.is404 === false
Normally, the
vite-plugin-ssr
source code doesn't know anything aboutpageContext.pageProps
but this is the only exception.
That way, we can use pageContext.pageProps.is404
to decide what error message to show our user:
// _error.page.js
export { Page }
function Page(pageProps) {
if (pageProps.is404) {
// UI component showing the user a message like "Page Not Found"
} else {
// UI component showing the user a message like "Our server is down, sincere apologies."
}
}
We can define _error.page.js
like any other page, for example with _error.page.client.js
and _error.page.server.js
.