Я пытаюсь вывести сообщение об ошибке в приложении nextJS:
/ страницы / index.js
class page extends Component {
componentDidMount () {
throw new Error('My error message')
}
render () {
return <div>something</div>
}
}
/ страницы / _error.js
export default class Error extends React.Component {
static getInitialProps ({ res, xhr }) {
const statusCode = res ? res.statusCode : (xhr ? xhr.status : null)
return { statusCode }
}
render () {
return (
<div>{
this.props.statusCode
? `${this.props.statusCode} not found`
: 'An error occurred on client' // <-- output of error message
}</div>
)
}
}
Я хотел бы вывести пользовательское сообщение об ошибке на странице индекса. Это возможно?