{"id":16462,"date":"2022-01-20T15:01:22","date_gmt":"2022-01-20T06:01:22","guid":{"rendered":"http:\/\/www.code-magagine.com\/?p=16462"},"modified":"2023-05-27T21:29:58","modified_gmt":"2023-05-27T12:29:58","slug":"%e3%80%90next-js%e3%80%91%e3%80%8c%e3%82%a8%e3%83%a9%e3%83%bc%e3%83%8f%e3%83%b3%e3%83%89%e3%83%aa%e3%83%b3%e3%82%b0%e3%80%8d","status":"publish","type":"post","link":"http:\/\/www.code-magagine.com\/?p=16462","title":{"rendered":"\u3010Next.js\u3011\u300c\u30a8\u30e9\u30fc\u30cf\u30f3\u30c9\u30ea\u30f3\u30b0\u300d"},"content":{"rendered":"<h2>Error Boundary<\/h2>\n<p>\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u3067\u767a\u751f\u3059\u308b\u7279\u5b9a\u306e\u30a8\u30e9\u30fc\uff08\u5b9f\u884c\u6642\u30a8\u30e9\u30fc\u306a\u3069\uff09\u3057\u304bcatch\u3057\u3066\u304f\u308c\u306a\u3044\u3002\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u306f\u6355\u6349\u3057\u306a\u3044\u306e\u3067\u3001\u73fe\u72b6\u306f\u3042\u307e\u308a\u4f7f\u3044\u9053\u306f\u306a\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u3002<\/p>\n<ul>\n<li>\u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u5185\u3067\u767a\u751f\u3057\u305f\u30a8\u30e9\u30fc<\/li>\n<li>fetch API\u3067\u5e30\u3063\u3066\u304d\u305f\u30a8\u30e9\u30fc\u306a\u3069\u3002<\/li>\n<\/ul>\n<h2>next\/error<\/h2>\n<p>Next.js\u3067\u306f\u30c7\u30d5\u30a9\u30eb\u30c8\u3067\u30a8\u30e9\u30fc\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8(Error)\u304c\u5b58\u5728\u3057\u307e\u3059\u3002Next.js\u304c\u7528\u610f\u3057\u3066\u3044\u308bError\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u518d\u5229\u7528\u3057\u305f\u3044\u5834\u5408\u306f\u3053\u308c\u3092\u4f7f\u3046\u3002<\/p>\n<h3>pages\/_error.js<\/h3>\n<p>\u30c7\u30d5\u30a9\u30eb\u30c8\u306eError\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\uff08\u4e0a\u66f8\u304d\uff09\u3057\u305f\u3044\u5834\u5408\u306f\u914d\u7f6e\u3057\u307e\u3059\u3002\u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u30ec\u30f3\u30c0\u30ea\u30f3\u30b0\u3055\u308c\u308b\u3002\u3061\u306a\u307f\u306b\u3053\u308c\u306f\u672c\u756a\u30d3\u30eb\u30c9\u6642\u306e\u307f\u5229\u7528\u3055\u308c\u307e\u3059\u3002\uff08\u958b\u767a\u6642\u306f\u5229\u7528\u3055\u308c\u307e\u305b\u3093\u3002\uff09<\/p>\n<div>\n<div>\n<pre class=\"lang:default decode:true\">function Error({ statusCode }) {\r\n  return (\r\n    &lt;p&gt;\r\n      {statusCode\r\n        ? `An error ${statusCode} occurred on server`\r\n        : 'An error occurred on client'}\r\n    &lt;\/p&gt;\r\n  )\r\n}\r\n\r\nError.getInitialProps = ({ res, err }) =&gt; {\r\n  const statusCode = res ? res.statusCode : err ? err.statusCode : 404\r\n  return { statusCode }\r\n}\r\n\r\nexport default Error<\/pre>\n<div>\u300cgetStaticProps\u300d\u3084\u300cgetServerProps\u300d\u306a\u3069\u3067\u30c7\u30fc\u30bf\u304c\u53d6\u308c\u306a\u304b\u3063\u305f\u5834\u5408\u3084\u3001\u4efb\u610f\u306e\u30a8\u30e9\u30fc\u3092\u8868\u793a\u3055\u305b\u305f\u3044\u5834\u5408\u3053\u308c\u3092\u4f7f\u3046\u3002<\/div>\n<\/div>\n<\/div>\n<h2>pages\/404.js<\/h2>\n<p>\u5b58\u5728\u3057\u306a\u3044URL\u306b\u30a2\u30af\u30bb\u30b9\u3057\u305f\u969b\u306e\u30da\u30fc\u30b8\u3092\u8fd4\u3059\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002\u516c\u5f0f\u3067\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30da\u30fc\u30b8\u3092\u4f5c\u6210\u3057\u3066\u3044\u307e\u3059\u3002\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u305f\u3089\u30d3\u30eb\u30c9\u6642\u306b\u9759\u7684\u306b\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">export default function Custom404() {\r\n  return &lt;h1&gt;404 - \u6307\u5b9a\u3057\u305f\u30da\u30fc\u30b8\u304c\u898b\u3064\u304b\u308a\u307e\u305b\u3093\u3067\u3057\u305f\u3002&lt;\/h1&gt;;\r\n}<\/pre>\n<h2>pages\/500.js<\/h2>\n<p>\u30b5\u30fc\u30d0\u30fc\u5074\u3067\u767a\u751f\u3057\u305f\u30a8\u30e9\u30fc\u3092\u6355\u6349\u3057\u305f\u3044\u5834\u5408\u306f\u4ee5\u4e0b\u306e\u30da\u30fc\u30b8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002\u3053\u306e\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3057\u305f\u3089\u30d3\u30eb\u30c9\u6642\u306b\u9759\u7684\u306b\u751f\u6210\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true \">export default function Custom500() {\r\n  return &lt;h1&gt;500 - \u30b5\u30fc\u30d0\u30fc\u30b5\u30a4\u30c9\u3067\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3057\u307e\u3057\u305f\u3002&lt;\/h1&gt;\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"Error Boundary \u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u5185\u3067\u767a\u751f\u3059\u308b\u7279\u5b9a\u306e\u30a8\u30e9\u30fc\uff08\u5b9f\u884c\u6642\u30a8\u30e9\u30fc\u306a\u3069\uff09\u3057\u304bcatch\u3057\u3066\u304f\u308c\u306a\u3044\u3002\u4ee5\u4e0b\u306e\u30a8\u30e9\u30fc\u306f\u6355\u6349\u3057\u306a\u3044\u306e\u3067\u3001\u73fe\u72b6\u306f\u3042\u307e\u308a\u4f7f\u3044\u9053\u306f\u306a\u3044\u304b\u3082\u3057\u308c\u306a\u3044\u3002 \u30a4\u30d9\u30f3\u30c8\u30cf\u30f3\u30c9\u30e9\u5185\u3067\u767a\u751f\u3057\u305f\u30a8\u30e9\u30fc [&hellip;]","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[119],"tags":[],"_links":{"self":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/16462"}],"collection":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=16462"}],"version-history":[{"count":6,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/16462\/revisions"}],"predecessor-version":[{"id":20366,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=\/wp\/v2\/posts\/16462\/revisions\/20366"}],"wp:attachment":[{"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=16462"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=16462"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.code-magagine.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=16462"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}