Skip to content

Commit 0a14828

Browse files
authored
fix(b-link): remove default values from vue-router pass-down props (closes bootstrap-vue#6373) (bootstrap-vue#6374)
* fix(b-link): remove default values from `vue-router` passdown props * Update link.js * Update link.js
1 parent 11617b4 commit 0a14828

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/components/link/link.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { concat } from '../../utils/array'
1111
import { attemptBlur, attemptFocus, isTag } from '../../utils/dom'
1212
import { getRootEventName, stopEvent } from '../../utils/events'
1313
import { isBoolean, isEvent, isFunction, isUndefined } from '../../utils/inspect'
14-
import { sortKeys } from '../../utils/object'
14+
import { omit, sortKeys } from '../../utils/object'
1515
import { makeProp, makePropsConfigurable, pluckProps } from '../../utils/props'
1616
import { computeHref, computeRel, computeTag, isRouterLink } from '../../utils/router'
1717
import { attrsMixin } from '../../mixins/attrs'
@@ -29,11 +29,11 @@ const ROOT_EVENT_NAME_CLICKED = getRootEventName(NAME_LINK, 'clicked')
2929
export const routerLinkProps = {
3030
activeClass: makeProp(PROP_TYPE_STRING),
3131
append: makeProp(PROP_TYPE_BOOLEAN, false),
32-
event: makeProp(PROP_TYPE_ARRAY_STRING, EVENT_NAME_CLICK),
32+
event: makeProp(PROP_TYPE_ARRAY_STRING),
3333
exact: makeProp(PROP_TYPE_BOOLEAN, false),
3434
exactActiveClass: makeProp(PROP_TYPE_STRING),
3535
replace: makeProp(PROP_TYPE_BOOLEAN, false),
36-
routerTag: makeProp(PROP_TYPE_STRING, 'a'),
36+
routerTag: makeProp(PROP_TYPE_STRING),
3737
to: makeProp(PROP_TYPE_OBJECT_STRING)
3838
}
3939

@@ -98,14 +98,18 @@ export const BLink = /*#__PURE__*/ Vue.extend({
9898
return computeHref({ to, href }, this.computedTag)
9999
},
100100
computedProps() {
101-
const { prefetch } = this
101+
const { event, prefetch, routerTag } = this
102102
return this.isRouterLink
103103
? {
104-
...pluckProps({ ...routerLinkProps, ...nuxtLinkProps }, this),
105-
// Coerce `prefetch` value `null` to be `undefined`
106-
prefetch: isBoolean(prefetch) ? prefetch : undefined,
104+
...pluckProps(
105+
omit({ ...routerLinkProps, ...nuxtLinkProps }, ['event', 'prefetch', 'routerTag']),
106+
this
107+
),
108+
// Only add these props, when actually defined
109+
...(event ? { event } : {}),
110+
...(isBoolean(prefetch) ? { prefetch } : {}),
107111
// Pass `router-tag` as `tag` prop
108-
tag: this.routerTag
112+
...(routerTag ? { tag: routerTag } : {})
109113
}
110114
: {}
111115
},
@@ -127,7 +131,7 @@ export const BLink = /*#__PURE__*/ Vue.extend({
127131
// (i.e. if `computedHref` is truthy)
128132
...(href ? { href } : {}),
129133
// We don't render `rel` or `target` on non link tags when using `vue-router`
130-
...(isRouterLink && !isTag(routerTag, 'a') ? {} : { rel, target }),
134+
...(isRouterLink && routerTag && !isTag(routerTag, 'a') ? {} : { rel, target }),
131135
tabindex: disabled ? '-1' : isUndefined(bvAttrs.tabindex) ? null : bvAttrs.tabindex,
132136
'aria-disabled': disabled ? 'true' : null
133137
}
@@ -153,10 +157,10 @@ export const BLink = /*#__PURE__*/ Vue.extend({
153157
// Needed to prevent `vue-router` for doing its thing
154158
stopEvent(event, { immediatePropagation: true })
155159
} else {
160+
// Router links do not emit instance `click` events, so we
161+
// add in an `$emit('click', event)` on its Vue instance
156162
/* istanbul ignore next: difficult to test, but we know it works */
157163
if (isRouterLink && event.currentTarget.__vue__) {
158-
// Router links do not emit instance `click` events, so we
159-
// add in an `$emit('click', event)` on its Vue instance
160164
event.currentTarget.__vue__.$emit(EVENT_NAME_CLICK, event)
161165
}
162166
// Call the suppliedHandler(s), if any provided

0 commit comments

Comments
 (0)