-
Notifications
You must be signed in to change notification settings - Fork 2
/
smart-link.js
66 lines (60 loc) · 1.92 KB
/
smart-link.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _index = require('./index');
// Generated by CoffeeScript 2.2.4
// Render a nuxt-link if an internal link or a v-parse-anchor wrapped a if not.
// This is so that link pre-fetching works.
var _extends = Object.assign || function (target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i];for (var key in source) {
if (Object.prototype.hasOwnProperty.call(source, key)) {
target[key] = source[key];
}
}
}return target;
};
exports.default = {
name: 'SmartLink',
functional: true,
props: {
to: String // The URL gets passed here
},
// Destructure the props and data we care about
render: function render(create, _ref) {
var to = _ref.props.to,
data = _ref.data,
listeners = _ref.listeners,
children = _ref.children,
parent = _ref.parent;
var ref, ref1;
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: (0, _index.makeRouterPath)(to, {
router: parent != null ? parent.$router : void 0
})
}
}), children);
} else {
// Make a standard link that opens in a new window
return create('a', _extends({}, data, {
attrs: _extends({}, data.attrs, {
href: to,
target: (0, _index.shouldOpenInNewWindow)(to) ? '_blank' : void 0
})
}), children);
}
}
};