开发模式支持History路由
parent
a961c52c05
commit
96bee5184a
17
lib/dev.js
17
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])
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue