From ad753d04d6328483d0643cbd2ea0cb24f9025e6b Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Mon, 28 Aug 2017 10:05:52 -0300 Subject: [PATCH 1/4] Update link.js --- lib/components/link.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/components/link.js b/lib/components/link.js index f39b2efa862..72d30536403 100644 --- a/lib/components/link.js +++ b/lib/components/link.js @@ -93,8 +93,10 @@ function computeHref({ disabled, href, to }) { if (disabled) return "#"; // If href explicitly provided if (href) return href; - // Fallback to `to` prop + // Fallback to `to` prop (if `to` is a string) if (to && typeof to === "string") return to; + // Fallback to `to.path` prop (if `to` is an object) + if (to && typeof to === "object" && typeof to.path === 'string') return to.path; // If nothing is provided use '#' return '#' } From 5b90813951dca6bcb861992d9cfd6c687bee46d4 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Mon, 28 Aug 2017 10:58:10 -0300 Subject: [PATCH 2/4] check parent.$router --- lib/components/link.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/components/link.js b/lib/components/link.js index 72d30536403..cfa1f3380b4 100644 --- a/lib/components/link.js +++ b/lib/components/link.js @@ -89,14 +89,16 @@ function computeTag(props) { return 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` is a string) - if (to && typeof to === "string") return to; - // Fallback to `to.path` prop (if `to` is an object) - if (to && typeof to === "object" && typeof to.path === 'string') return to.path; + 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 '#' } @@ -141,7 +143,7 @@ export default { render(h, { props, data, parent, children }) { const tag = computeTag(props), 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 }) }; From a7348ab8d3429ad7aed2dadb736fdddd738559dd Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Wed, 30 Aug 2017 16:29:13 -0300 Subject: [PATCH 3/4] check for parent.$router when compuring tag to use --- lib/components/link.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/components/link.js b/lib/components/link.js index cfa1f3380b4..fc5fa89f89d 100644 --- a/lib/components/link.js +++ b/lib/components/link.js @@ -85,8 +85,8 @@ export const computed = { } }; -function computeTag(props) { - return props.to && !props.disabled ? "router-link" : "a"; +function computeTag(props, parent) { + return Boooean(parent.$router) && props.to && !props.disabled ? "router-link" : "a"; } function computeHref({ disabled, href, to }, parent) { @@ -141,7 +141,7 @@ 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, parent), eventType = tag === "router-link" ? "nativeOn" : "on", From 9a000fbbcec878ae768fcfb122ee216cc7a16fb6 Mon Sep 17 00:00:00 2001 From: Troy Morehouse Date: Wed, 30 Aug 2017 17:33:21 -0300 Subject: [PATCH 4/4] ESLint --- lib/components/link.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/components/link.js b/lib/components/link.js index fc5fa89f89d..2782f53cef3 100644 --- a/lib/components/link.js +++ b/lib/components/link.js @@ -86,7 +86,7 @@ export const computed = { }; function computeTag(props, parent) { - return Boooean(parent.$router) && props.to && !props.disabled ? "router-link" : "a"; + return (Boolean(parent.$router) && props.to && !props.disabled) ? "router-link" : "a"; } function computeHref({ disabled, href, to }, parent) {