定制错误页
import Error from 'next/error';
export default function Index({ result }) {
const { success, data } = result;
if (!success) {
return <Error statusCode={500} title="出错了" />;
}
return (
<>
<style jsx>
{`
.list {
margin: 30px;
}
`}
</style>
<ul className="list">
{data.map(item => (
<li key={item.id}>{item.title}</li>
))}
</ul>
</>
);
}
export async function getServerSideProps(context) {
const response = await fetch('https://cnodejs.org/api/v1/topics');
const result = await response.json();
return {
props: { result },
};
}