@@ -57,12 +57,17 @@ const observer =
57
57
} )
58
58
: null
59
59
60
- export function createComponent ( { isOffline, router, route } ) {
60
+ export function createComponent ( { isOffline, router, route, fetchPayload } ) {
61
61
return class Hit extends Component {
62
62
handleId = null ;
63
63
observed = false ;
64
64
link = createRef ( ) ;
65
65
66
+ constructor ( { hit } ) {
67
+ super ( )
68
+ this . url = normalizeURL ( hit . url )
69
+ }
70
+
66
71
canPrefetch ( ) {
67
72
const conn = navigator . connection
68
73
const hasBadConnection =
@@ -73,8 +78,7 @@ export function createComponent ({ isOffline, router, route }) {
73
78
}
74
79
75
80
getPrefetchComponents ( ) {
76
- const { hit } = this . props
77
- const ref = router . resolve ( normalizeURL ( hit . url ) , route )
81
+ const ref = router . resolve ( this . url , route )
78
82
const Components = ref . resolved . matched . map ( r => r . components . default )
79
83
80
84
return Components . filter (
@@ -100,6 +104,11 @@ export function createComponent ({ isOffline, router, route }) {
100
104
}
101
105
Component . __prefetched = true
102
106
}
107
+
108
+ if ( fetchPayload ) {
109
+ const { href } = router . resolve ( this . url , route )
110
+ fetchPayload ( href , true ) . catch ( ( ) => { } )
111
+ }
103
112
}
104
113
105
114
observe ( el ) {
@@ -134,9 +143,8 @@ export function createComponent ({ isOffline, router, route }) {
134
143
}
135
144
136
145
render ( { hit, children } ) {
137
- const url = normalizeURL ( hit . url )
138
146
return createElement ( 'a' , {
139
- href : url ,
147
+ href : this . url ,
140
148
ref : this . link ,
141
149
onClick : event => {
142
150
if ( isSpecialClick ( event ) ) {
@@ -156,7 +164,7 @@ export function createComponent ({ isOffline, router, route }) {
156
164
if ( router . history . current . path !== hitPathname ) {
157
165
event . preventDefault ( )
158
166
}
159
- router . push ( url )
167
+ router . push ( this . url )
160
168
} ,
161
169
children
162
170
} )
0 commit comments