From 147a5ce64198cddab852bc5a297e877de2c9f29c Mon Sep 17 00:00:00 2001 From: Arunoda Susiripala Date: Mon, 8 May 2017 23:38:36 -0700 Subject: [PATCH] Fix server rendering issue for normal apps. --- lib/link.js | 1 + server/render.js | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/link.js b/lib/link.js index af0e1d93..ab9a4d6d 100644 --- a/lib/link.js +++ b/lib/link.js @@ -133,6 +133,7 @@ export default class Link extends Component { // "/index.html" directly. const endsWithSlash = /\/$/.test(props.href) if ( + typeof __NEXT_DATA__ !== 'undefined' && __NEXT_DATA__.nextExport && !endsWithSlash ) { diff --git a/server/render.js b/server/render.js index 47479d14..b29680dd 100644 --- a/server/render.js +++ b/server/render.js @@ -49,6 +49,13 @@ async function doRender (req, res, pathname, query, { const dist = getConfig(dir).distDir + // realPathname is pretty useful in the document.js + // In there, we include a proper valid resolved path. + // That helps us to server that JSON page directly from a static server. + // Basically, this is a requirment for next-export + const pageRealPath = await resolvePath(join(dir, dist, 'dist', 'pages', page)) + const realPathname = pageRealPath.replace(join(dir, dist, 'dist', 'pages'), '') + let [Component, Document] = await Promise.all([ requireModule(join(dir, dist, 'dist', 'pages', page)), requireModule(join(dir, dist, 'dist', 'pages', '_document')) @@ -91,13 +98,6 @@ async function doRender (req, res, pathname, query, { if (res.finished) return - // realPathname is pretty useful in the document.js - // In there, we include a proper valid resolved path. - // That helps us to server that JSON page directly from a static server. - // Basically, this is a requirment for next-export - const pageRealPath = await resolvePath(join(dir, 'pages', pathname)) - const realPathname = pageRealPath.replace(join(dir, 'pages'), '') - const doc = createElement(Document, { __NEXT_DATA__: { props,