diff --git a/lib/components/link.js b/lib/components/link.js index f39b2efa862..2782f53cef3 100644 --- a/lib/components/link.js +++ b/lib/components/link.js @@ -85,16 +85,20 @@ export const computed = { } }; -function computeTag(props) { - return props.to && !props.disabled ? "router-link" : "a"; +function computeTag(props, parent) { + return (Boolean(parent.$router) && props.to && !props.disabled) ? "router-link" : "a"; } -function computeHref({ disabled, href, to }) { +function computeHref({ disabled, href, to }, parent) { if (disabled) return "#"; // If href explicitly provided if (href) return href; - // Fallback to `to` prop - if (to && typeof to === "string") return to; + if (to && !Boolean(parent.$router)) { + // Fallback to `to` prop (if `to` is a string) + if (typeof to === "string") return to; + // Fallback to `to.path` prop (if `to` is an object) + if (typeof to === "object" && typeof to.path === 'string') return to.path; + } // If nothing is provided use '#' return '#' } @@ -137,9 +141,9 @@ export default { functional: true, props: propsFactory(), render(h, { props, data, parent, children }) { - const tag = computeTag(props), + const tag = computeTag(props, parent), rel = computeRel(props), - href = computeHref(props), + href = computeHref(props, parent), eventType = tag === "router-link" ? "nativeOn" : "on", suppliedHandler = (data[eventType] || {}).click, handlers = { click: clickHandlerFactory({ tag, href, disabled: props.disabled, suppliedHandler, parent }) };