Skip to content

Commit

Permalink
pr changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilson Lemos authored and Wilson Lemos committed Apr 20, 2022
1 parent 7f8ed25 commit 7a8fdc8
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import URL from 'url-parse'
# Default settings
settings =
addBlankToExternal: false
addTrailingSlashToInternal: false
internalUrls: []
sameWindowUrls: []
internalHosts: []
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var bind,
// Default settings
settings = {
addBlankToExternal: false,
addTrailingSlashToInternal: false,
internalUrls: [],
sameWindowUrls: [],
internalHosts: [],
Expand Down Expand Up @@ -183,6 +184,8 @@ var addTrailingSlash = exports.addTrailingSlash = function addTrailingSlash(to)
};

exports.default = {
// if to.match /\/$/ then to else to + '/'

// Directive definition with settings method for overriding the default settings.
// I'm relying on Browser garbage collection to cleanup listeners.
bind: bind,
Expand Down
1 change: 1 addition & 0 deletions nuxt/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = function (options) {

// Accept options from module or config
options = {...options, ...this.options.anchorParser}
this.options.publicRuntimeConfig.anchorParser = options

// Register a plugin that applys the settings for SSR and non-SSR
this.addPlugin({
Expand Down
6 changes: 3 additions & 3 deletions smart-link.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ export default

props:
to: String # The URL gets passed here
internalTrailingSlash: Boolean # Optionally add trailing slash if is internal link

# Destructure the props and data we care about
render: (create, {
props: { to, internalTrailingSlash }
props: { to }
data
listeners
children
parent
}) ->
# If no "to", wrap children in a span so that children are nested
# consistently
Expand All @@ -30,7 +30,7 @@ export default
...data
nativeOn: listeners # nuxt-link doesn't forward events on it's own
props:
to: if internalTrailingSlash
to: if parent?.$config?.anchorParser?.addTrailingSlashToInternal
then makeRouterPath addTrailingSlash to
else makeRouterPath to
}, children
Expand Down
13 changes: 6 additions & 7 deletions smart-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ exports.default = {
name: 'SmartLink',
functional: true,
props: {
to: String, // The URL gets passed here
internalTrailingSlash: Boolean // Optionally add trailing slash if is internal link
to: String // The URL gets passed here
},

// Destructure the props and data we care about
render: function render(create, _ref) {
var _ref$props = _ref.props,
to = _ref$props.to,
internalTrailingSlash = _ref$props.internalTrailingSlash,
var to = _ref.props.to,
data = _ref.data,
listeners = _ref.listeners,
children = _ref.children;
children = _ref.children,
parent = _ref.parent;

var ref, ref1;
if (!to) {
return create('span', data, children);
}
Expand All @@ -45,7 +44,7 @@ exports.default = {
return create('nuxt-link', _extends({}, data, {
nativeOn: listeners, // nuxt-link doesn't forward events on it's own
props: {
to: internalTrailingSlash ? (0, _index.makeRouterPath)((0, _index.addTrailingSlash)(to)) : (0, _index.makeRouterPath)(to)
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)
}
}), children);
} else {
Expand Down

0 comments on commit 7a8fdc8

Please sign in to comment.