Skip to content

Commit

Permalink
1.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
weotch committed Jun 25, 2022
1 parent 543cb54 commit 7e81dd4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
15 changes: 12 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ makeUrlObj = function makeUrlObj(url) {
// open in a new window.
handleInternal = function handleInternal(anchor, url, router) {
var path;
path = makeRouterPath(url);
path = makeRouterPath(url, { router: router });
if (router.resolve({ path: path }).route.matched.length) {
return anchor.addEventListener('click', function (e) {
e.preventDefault();
Expand All @@ -142,9 +142,18 @@ handleInternal = function handleInternal(anchor, url, router) {

// Make routeable path
var makeRouterPath = exports.makeRouterPath = function makeRouterPath(url) {
var urlObj;
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
router = _ref.router;

var base, path, ref, urlObj;
urlObj = makeUrlObj(url);
return '' + urlObj.pathname + urlObj.query + urlObj.hash;
// Remove the router.base from the path, if it exists
path = urlObj.pathname;
if ((base = router != null ? (ref = router.options) != null ? ref.base : void 0 : void 0) && path.indexOf(base) === 0) {
path = '/' + path.slice(base.length);
}
// Create path with query and hash
return '' + path + urlObj.query + urlObj.hash;
};

// Add target blank to external links
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-routing-anchor-parser",
"version": "1.14.1",
"version": "1.15.0",
"description": "A Vue directive that parses child elements for internally linking anchor tags and binds their click events to use Vue Router's push().",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 7 additions & 3 deletions smart-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,18 @@ exports.default = {
if (!to) {
return create('span', data, children);
}
// Add trailing slashes if configured to
if (parent != null ? (ref = parent.$config) != null ? (ref1 = ref.anchorParser) != null ? ref1.addTrailingSlashToInternal : void 0 : void 0 : void 0) {
to = (0, _index.addTrailingSlash)(to);
}
// Test if an internal link
if ((0, _index.isInternal)(to)) {
// Render a nuxt-link
return create('nuxt-link', _extends({}, data, {
nativeOn: listeners, // nuxt-link doesn't forward events on it's own
props: {
to: (parent != null ? (ref = parent.$config) != null ? (ref1 = ref.anchorParser) != null ? ref1.addTrailingSlashToInternal : void 0 : void 0 : void 0) ? (0, _index.makeRouterPath)((0, _index.addTrailingSlash)(to)) : (0, _index.makeRouterPath)(to)
}
props: (0, _index.makeRouterPath)(to, {
router: parent != null ? parent.$router : void 0
})
}), children);
} else {
// Make a standard link that opens in a new window
Expand Down

0 comments on commit 7e81dd4

Please sign in to comment.