【发布时间】:2019-11-14 12:36:52
【问题描述】:
API 端点 (Express) 发送 404。return res.status(404).json({ message: 'Not Found !!!' })
在_app 组件中
static async getInitialProps({ Component, ctx }) {
try {
const pageProps = Component.getInitialProps
? await Component.getInitialProps(ctx)
: {}
const statusCode = ctx.res && ctx.res.statusCode
return {
pageProps,
statusCode
}
} catch (err) {
// What to do here?
}
应用组件在另一个组件中调用getInitialProps...这里调用了返回404状态的API。
static async getInitialProps(ctx) {
try {
const response = await axios.get(route.API_POST(id))
// do something with response
} catch (err) {
//???????
}
}
只有,它没有。它返回200。
当 Express 端点返回 404 状态时,如何在 NextJS 中呈现 404 页面?
【问题讨论】:
标签: next.js