1.

How to create pages in next js?

Answer»

6. How to create a custom error page in next js?

  • To create a custom error page in Next JS, we have to define a “_error.js” in the page folder with this given syntax.
  • We have to import our own “_ error” component INSTEAD of “next/error” further to use our custom error page.
Example

import React from 'react';

CLASS Error extends React.Component {

     static getInitialProps({ RES, err }) {

        CONST statusCode = res ? res.statusCode : err ? err.statusCode : null;

      return { statusCode };

}

RENDER() {

return (

<p>

   {this.props.statusCode

   ? `An error ${this.props.statusCode} occurred on server`

   : 'An error occurred on client'}

</p>

    );

  }

}

export default Error;



Discussion

No Comment Found