From a70620387953f8f50bc0e7564610f38c029b76b2 Mon Sep 17 00:00:00 2001 From: Bojan Djurkovic Date: Fri, 31 Mar 2017 09:08:05 -0300 Subject: [PATCH] add optional current route param to toURL and use it to properly compose local anchor links --- src/core/render/compiler.js | 2 +- src/core/route/hash.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index 0462f19..4c7c045 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -82,7 +82,7 @@ renderer.code = function (code, lang = '') { renderer.link = function (href, title, text) { let blank = '' if (!/:|(\/{2})/.test(href)) { - href = toURL(href) + href = toURL(href, null, currentPath) } else { blank = ' target="_blank"' } diff --git a/src/core/route/hash.js b/src/core/route/hash.js index fd725b8..417ae96 100644 --- a/src/core/route/hash.js +++ b/src/core/route/hash.js @@ -64,16 +64,17 @@ export function parse (path = window.location.href) { * to URL * @param {string} path * @param {object} qs query params + * @param {string} currentRoute optional current route */ -export function toURL (path, params) { - const inline = path[0] === '#' +export function toURL (path, params, currentRoute) { + const local = currentRoute && path[0] === '#' const route = parse(replaceSlug(path)) route.query = merge({}, route.query, params) path = route.path + stringifyQuery(route.query) path = path.replace(/\.md(\?)|\.md$/, '$1') - if (inline) path = currentPath + path + if (local) path = currentRoute + path return cleanPath('#/' + path) }