Skip to content

Commit dbcea25

Browse files
committed
feat: perfect solution
1 parent 613ea7f commit dbcea25

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

lib/app/app.js

-7
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,6 @@ export function createApp () {
6767

6868
// redirect /foo to /foo/
6969
router.beforeEach((to, from, next) => {
70-
const decodedPath = decodeURIComponent(to.path)
71-
if (decodedPath !== to.path) {
72-
next(Object.assign({}, to, {
73-
fullPath: decodeURIComponent(to.fullPath),
74-
path: decodedPath
75-
}))
76-
}
7770
if (!/(\/|\.html)$/.test(to.path)) {
7871
next(Object.assign({}, to, {
7972
path: to.path + '/'

lib/prepare.js

+14-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ async function resolveOptions (sourceDir) {
199199
const key = 'v-' + Math.random().toString(16).slice(2)
200200
const data = {
201201
key,
202-
path: fileToPath(file)
202+
path: encodePath(fileToPath(file))
203203
}
204204

205205
if (shouldResolveLastUpdated) {
@@ -329,6 +329,15 @@ async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) {
329329
}
330330
}`
331331

332+
const dncodedPath = decodeURIComponent(pagePath)
333+
if (dncodedPath !== pagePath) {
334+
code += `,
335+
{
336+
path: ${JSON.stringify(dncodedPath)},
337+
redirect: ${JSON.stringify(pagePath)}
338+
}`
339+
}
340+
332341
if (/\/$/.test(pagePath)) {
333342
code += `,
334343
{
@@ -365,6 +374,10 @@ function sort (arr) {
365374
})
366375
}
367376

377+
function encodePath (path) {
378+
return path.split('/').map(item => encodeURIComponent(item)).join('/')
379+
}
380+
368381
async function parseConfig (file) {
369382
const content = await fs.readFile(file, 'utf-8')
370383
const [extension] = /.\w+$/.exec(file)

0 commit comments

Comments
 (0)