Skip to content

Commit 8fefc9f

Browse files
author
reco_luan
committed
fix(vuepress-theme-reco): fix bug of non-ASCII file names cause 404
ISSUES CLOSED: #276, #281
1 parent a6e28b0 commit 8fefc9f

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

example/views/category1/2018/121501.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ date: 2018-12-15
44
tags:
55
- tag1
66
categories:
7-
- category1
7+
- 分类
88
---
99

1010
first page in category1

packages/vuepress-theme-reco/enhanceApp.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import postMixin from '@theme/mixins/posts'
33
import localMixin from '@theme/mixins/locales'
44
import { addLinkToHead, addScriptToHead } from '@theme/helpers/utils'
5-
import { registerCodeThemeCss, interceptRouterError } from '@theme/helpers/other'
5+
import { registerCodeThemeCss, interceptRouterError, fixRouterError404 } from '@theme/helpers/other'
66
import { install } from 'vue-demi'
77

88
export default ({
@@ -21,4 +21,5 @@ export default ({
2121
}
2222

2323
interceptRouterError(router)
24+
fixRouterError404(router)
2425
}

packages/vuepress-theme-reco/helpers/other.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,18 @@ export function interceptRouterError (router) {
3434
return originalPush.call(this, location).catch(err => err)
3535
}
3636
}
37+
38+
export function fixRouterError404 (router) {
39+
router.beforeEach((to, from, next) => {
40+
// 解决非ASCII文件名的路由, 防止 404
41+
const decodedPath = decodeURIComponent(to.path)
42+
if (decodedPath !== to.path) {
43+
next(Object.assign({}, to, {
44+
fullPath: decodeURIComponent(to.fullPath),
45+
path: decodedPath
46+
}))
47+
} else {
48+
next()
49+
}
50+
})
51+
}

0 commit comments

Comments
 (0)