From 96bee5184a0790e644664bfea8cc569298391bba Mon Sep 17 00:00:00 2001 From: yutent Date: Thu, 29 Dec 2022 17:07:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E6=A8=A1=E5=BC=8F=E6=94=AF?= =?UTF-8?q?=E6=8C=81History=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/dev.js | 17 ++++++++++++++--- package.json | 3 ++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/dev.js b/lib/dev.js index 8996e86..99938ec 100644 --- a/lib/dev.js +++ b/lib/dev.js @@ -40,7 +40,7 @@ export default function createServer(root = '', conf = {}) { WEB_SERVER.createServer(SERVER_OPTIONS, function (req, res) { let pathname = parse(req.url.slice(1)).pathname let pageName = '', - isIndex = false + isIndex = false // 是否渲染目录页 let ext if (pathname) { @@ -57,8 +57,15 @@ export default function createServer(root = '', conf = {}) { currentPage = pageName pagesDir = dirname(conf.pages[pageName].entry) } else { - ext = pathname.at(-1).split('.').pop() - pageName = currentPage + if (currentPage) { + ext = pathname.at(-1).split('.').pop() + pageName = currentPage + } else { + pageName = Object.keys(conf.pages).pop() + currentPage = pageName + pagesDir = dirname(conf.pages[pageName].entry) + ext = 'html' + } } pathname = pathname.join('/') } else { @@ -71,6 +78,10 @@ export default function createServer(root = '', conf = {}) { ext = 'html' } } + // 修正history路由时的访问 + if (pathname === ext) { + ext = 'html' + } for (let k in COMMON_HEADERS) { res.setHeader(k, COMMON_HEADERS[k]) diff --git a/package.json b/package.json index 8483369..fa7c1db 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,13 @@ { "name": "@bytedo/vue-live", "type": "module", - "version": "0.0.13", + "version": "0.0.14", "bin": { "vue-live": "index.js" }, "dependencies": { "@bytedo/sass": "^1.54.8", + "chokidar": "^3.5.3", "esbuild": "^0.15.13", "iofs": "^1.5.2" }