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" }