diff --git a/server/document.js b/server/document.js index 49eea8a5..6a27ffb2 100644 --- a/server/document.js +++ b/server/document.js @@ -84,12 +84,12 @@ export class Head extends Component { render () { const { head, styles, __NEXT_DATA__ } = this.context._documentProps - const { pathname, buildId, assetPrefix } = __NEXT_DATA__ + const { page, pathname, buildId, assetPrefix } = __NEXT_DATA__ const pagePathname = getPagePathname(pathname) return {(head || []).map((h, i) => React.cloneElement(h, { key: h.key || i }))} - + {page !== '_error' && } {this.getPreloadDynamicChunks()} {this.getPreloadMainLinks()} @@ -173,7 +173,7 @@ export class NextScript extends Component { render () { const { staticMarkup, __NEXT_DATA__, chunks } = this.context._documentProps - const { pathname, buildId, assetPrefix } = __NEXT_DATA__ + const { page, pathname, buildId, assetPrefix } = __NEXT_DATA__ const pagePathname = getPagePathname(pathname) __NEXT_DATA__.chunks = chunks.names @@ -193,9 +193,18 @@ export class NextScript extends Component { __NEXT_REGISTER_CHUNK = function (chunkName, fn) { __NEXT_LOADED_CHUNKS__.push({ chunkName: chunkName, fn: fn }) } + + ${page === '_error' && ` + __NEXT_REGISTER_PAGE('/index', function() { + var error = new Error('Page does not exist: ${htmlescape(pathname)}') + error.statusCode = 404 + + return { error: error } + }) + `} ` }} />} -