From 52e04c4f4eddc1bf13de1a8d507fcdbb1787fd77 Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 16 Apr 2018 12:24:56 -0400 Subject: [PATCH] fix: redirect */index.html to */ (close #83) --- lib/prepare.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/prepare.js b/lib/prepare.js index 3fd7b45376..00c65973fe 100644 --- a/lib/prepare.js +++ b/lib/prepare.js @@ -230,7 +230,7 @@ async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) { function genRoute ({ path: pagePath }, index) { const file = pageFiles[index] const filePath = path.resolve(sourceDir, file) - const code = ` + let code = ` { path: ${JSON.stringify(pagePath)}, component: Theme, @@ -241,6 +241,14 @@ async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) { }) } }` + + if (/\/$/.test(pagePath)) { + code += `,{ + path: ${JSON.stringify(pagePath + 'index.html')}, + redirect: ${JSON.stringify(pagePath)} + }` + } + return code }