@@ -85,19 +85,29 @@ export const computed = {
85
85
}
86
86
} ;
87
87
88
- function computeTag ( props ) {
89
- return props . to && ! props . disabled ? "router-link" : "a" ;
88
+ function computeTag ( props , parent ) {
89
+ return Boolean ( parent . $router ) && props . to && ! props . disabled ? "router-link" : "a" ;
90
90
}
91
91
92
92
function computeHref ( { disabled, href, to } , tag ) {
93
+ // We've already checked the parent.$router in computeTag,
94
+ // so router-link means live router.
93
95
// When deferring to Vue Router's router-link,
94
96
// don't use the href attr at all.
95
- if ( tag === "router-link" ) return null ;
97
+ // Must return undefined for router-link to populate href.
98
+ if ( tag === "router-link" ) return void 0 ;
96
99
if ( disabled ) return "#" ;
97
100
// If href explicitly provided
98
101
if ( href ) return href ;
102
+ // Reconstruct href when `to` used, but no router
103
+ if ( to ) {
104
+ // Fallback to `to` prop (if `to` is a string)
105
+ if ( typeof to === "string" ) return to ;
106
+ // Fallback to `to.path` prop (if `to` is an object)
107
+ if ( typeof to === "object" && typeof to . path === "string" ) return to . path ;
108
+ }
99
109
// If nothing is provided use '#'
100
- return '#'
110
+ return "#" ;
101
111
}
102
112
103
113
function computeRel ( { target, rel } ) {
@@ -138,7 +148,7 @@ export default {
138
148
functional : true ,
139
149
props : propsFactory ( ) ,
140
150
render ( h , { props, data, parent, children } ) {
141
- const tag = computeTag ( props ) ,
151
+ const tag = computeTag ( props , parent ) ,
142
152
rel = computeRel ( props ) ,
143
153
href = computeHref ( props , tag ) ,
144
154
eventType = tag === "router-link" ? "nativeOn" : "on" ,
0 commit comments