Skip to content

Commit

Permalink
feat: perfect solution
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed May 21, 2018
1 parent 613ea7f commit dbcea25
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
7 changes: 0 additions & 7 deletions lib/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,6 @@ export function createApp () {

// redirect /foo to /foo/
router.beforeEach((to, from, next) => {
const decodedPath = decodeURIComponent(to.path)
if (decodedPath !== to.path) {
next(Object.assign({}, to, {
fullPath: decodeURIComponent(to.fullPath),
path: decodedPath
}))
}
if (!/(\/|\.html)$/.test(to.path)) {
next(Object.assign({}, to, {
path: to.path + '/'
Expand Down
15 changes: 14 additions & 1 deletion lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async function resolveOptions (sourceDir) {
const key = 'v-' + Math.random().toString(16).slice(2)
const data = {
key,
path: fileToPath(file)
path: encodePath(fileToPath(file))
}

if (shouldResolveLastUpdated) {
Expand Down Expand Up @@ -329,6 +329,15 @@ async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) {
}
}`

const dncodedPath = decodeURIComponent(pagePath)
if (dncodedPath !== pagePath) {
code += `,
{
path: ${JSON.stringify(dncodedPath)},
redirect: ${JSON.stringify(pagePath)}
}`
}

if (/\/$/.test(pagePath)) {
code += `,
{
Expand Down Expand Up @@ -365,6 +374,10 @@ function sort (arr) {
})
}

function encodePath (path) {
return path.split('/').map(item => encodeURIComponent(item)).join('/')
}

async function parseConfig (file) {
const content = await fs.readFile(file, 'utf-8')
const [extension] = /.\w+$/.exec(file)
Expand Down

0 comments on commit dbcea25

Please sign in to comment.