Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/core/router/history/base.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import {
isAbsolutePath,
stringifyQuery,
cleanPath,
replaceSlug
replaceSlug,
resolvePath
} from '../util'
import {noop, merge} from '../../util/core'

Expand Down Expand Up @@ -76,6 +77,13 @@ export class History {
(idIndex > 0 ? currentRoute.substr(0, idIndex) : currentRoute) + path
}

return cleanPath('/' + path)
if (path.startsWith('/')) {
return cleanPath(path)
}

if (currentRoute !== undefined) {
const currentDir = currentRoute.substr(0, currentRoute.lastIndexOf('/') + 1)
return cleanPath(resolvePath(currentDir + path))
}
}
}
16 changes: 16 additions & 0 deletions src/core/router/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,19 @@ export function getPath(...args) {
export const replaceSlug = cached(path => {
return path.replace('#', '?id=')
})

export const resolvePath = cached(path => {
const segments = path.replace(/^\//, '').split('/')
let resolved = []

for (let i = 0, len = segments.length; i < len; i++) {
const segment = segments[i]

if (segment === '..') {
resolved.pop()
} else if (segment !== '.') {
resolved.push(segment)
}
}
return '/' + resolved.join('/')
})