diff --git a/src/core/router/history/base.js b/src/core/router/history/base.js old mode 100644 new mode 100755 index 0f9900d22..3d3b5b508 --- a/src/core/router/history/base.js +++ b/src/core/router/history/base.js @@ -3,7 +3,8 @@ import { isAbsolutePath, stringifyQuery, cleanPath, - replaceSlug + replaceSlug, + resolvePath } from '../util' import {noop, merge} from '../../util/core' @@ -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)) + } } } diff --git a/src/core/router/util.js b/src/core/router/util.js index 217461f47..117a090f4 100644 --- a/src/core/router/util.js +++ b/src/core/router/util.js @@ -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('/') +})