1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Add docs for next/error (#2513)

This commit is contained in:
Tim Neutkens 2017-07-09 06:54:27 +02:00 committed by Arunoda Susiripala
parent 86c283777f
commit dc607e452b

View file

@ -777,6 +777,37 @@ export default class Error extends React.Component {
}
```
### Reusing the build in error page
If you want to render the build in error page you can by using `next/error`:
```jsx
import React from 'react'
import Error from 'next/error'
import fetch from 'isomorphic-fetch'
export default class Page extends React.Component {
static async getInitialProps () {
const res = await fetch('https://api.github.com/repos/zeit/next.js')
const statusCode = res.statusCode > 200 ? res.statusCode : false
const json = await res.json()
return { statusCode, stars: json.stargazers_count }
}
render () {
if(this.props.statusCode) {
return <Error statusCode={this.props.statusCode} />
}
return (
<div>Next stars: {this.props.stars}</div>
)
}
}
```
> If you have created a custom error page you have to import your own `_error` component instead of `next/error`
### Custom configuration
For custom advanced behavior of Next.js, you can create a `next.config.js` in the root of your project directory (next to `pages/` and `package.json`).