@@ -424,9 +424,9 @@ async function _preload_data(intent) {
424
424
return load_cache . promise ;
425
425
}
426
426
427
- /** @param {string } pathname */
428
- async function _preload_code ( pathname ) {
429
- const route = routes . find ( ( route ) => route . exec ( get_url_path ( pathname ) ) ) ;
427
+ /** @param {URL } url */
428
+ async function _preload_code ( url ) {
429
+ const route = routes . find ( ( route ) => route . exec ( get_url_path ( url ) ) ) ;
430
430
431
431
if ( route ) {
432
432
await Promise . all ( [ ...route . layouts , route . leaf ] . map ( ( load ) => load ?. [ 1 ] ( ) ) ) ;
@@ -875,7 +875,7 @@ async function load_route({ id, invalidating, url, params, route, preload }) {
875
875
876
876
/** @type {import('types').ServerNodesResponse | import('types').ServerRedirectNode | null } */
877
877
let server_data = null ;
878
- const url_changed = current . url ? id !== current . url . pathname + current . url . search : false ;
878
+ const url_changed = current . url ? id !== get_page_key ( current . url ) : false ;
879
879
const route_changed = current . route ? route . id !== current . route . id : false ;
880
880
const search_params_changed = diff_search_params ( current . url , url ) ;
881
881
@@ -1175,7 +1175,12 @@ function get_navigation_intent(url, invalidating) {
1175
1175
// reroute could alter the given URL, so we pass a copy
1176
1176
let rerouted ;
1177
1177
try {
1178
- rerouted = app . hooks . reroute ( { url : new URL ( url ) } ) ?? url . pathname ;
1178
+ rerouted = app . hooks . reroute ( { url : new URL ( url ) } ) ?? url ;
1179
+
1180
+ if ( typeof rerouted === 'string' ) {
1181
+ url . pathname = rerouted ;
1182
+ rerouted = url ;
1183
+ }
1179
1184
} catch ( e ) {
1180
1185
if ( DEV ) {
1181
1186
// in development, print the error...
@@ -1195,7 +1200,7 @@ function get_navigation_intent(url, invalidating) {
1195
1200
const params = route . exec ( path ) ;
1196
1201
1197
1202
if ( params ) {
1198
- const id = url . pathname + url . search ;
1203
+ const id = get_page_key ( url ) ;
1199
1204
/** @type {import('./types.js').NavigationIntent } */
1200
1205
const intent = {
1201
1206
id,
@@ -1209,9 +1214,14 @@ function get_navigation_intent(url, invalidating) {
1209
1214
}
1210
1215
}
1211
1216
1212
- /** @param {string } pathname */
1213
- function get_url_path ( pathname ) {
1214
- return decode_pathname ( pathname . slice ( base . length ) || '/' ) ;
1217
+ /** @param {URL } url */
1218
+ function get_url_path ( url ) {
1219
+ return decode_pathname ( url . pathname . slice ( base . length ) || '/' ) ;
1220
+ }
1221
+
1222
+ /** @param {URL } url */
1223
+ function get_page_key ( url ) {
1224
+ return url . pathname + url . search ;
1215
1225
}
1216
1226
1217
1227
/**
@@ -1547,7 +1557,7 @@ function setup_preload() {
1547
1557
( entries ) => {
1548
1558
for ( const entry of entries ) {
1549
1559
if ( entry . isIntersecting ) {
1550
- _preload_code ( /** @type {HTMLAnchorElement } */ ( entry . target ) . href ) ;
1560
+ _preload_code ( new URL ( /** @type {HTMLAnchorElement } */ ( entry . target ) . href ) ) ;
1551
1561
observer . unobserve ( entry . target ) ;
1552
1562
}
1553
1563
}
@@ -1569,7 +1579,7 @@ function setup_preload() {
1569
1579
const options = get_router_options ( a ) ;
1570
1580
1571
1581
// we don't want to preload data for a page we're already on
1572
- const same_url = url && current . url . pathname + current . url . search === url . pathname + url . search ;
1582
+ const same_url = url && get_page_key ( current . url ) === get_page_key ( url ) ;
1573
1583
1574
1584
if ( ! options . reload && ! same_url ) {
1575
1585
if ( priority <= options . preload_data ) {
@@ -1591,7 +1601,7 @@ function setup_preload() {
1591
1601
}
1592
1602
}
1593
1603
} else if ( priority <= options . preload_code ) {
1594
- _preload_code ( /** @type {URL } */ ( url ) . pathname ) ;
1604
+ _preload_code ( /** @type {URL } */ ( url ) ) ;
1595
1605
}
1596
1606
}
1597
1607
}
@@ -1611,7 +1621,7 @@ function setup_preload() {
1611
1621
}
1612
1622
1613
1623
if ( options . preload_code === PRELOAD_PRIORITIES . eager ) {
1614
- _preload_code ( /** @type {URL } */ ( url ) . pathname ) ;
1624
+ _preload_code ( /** @type {URL } */ ( url ) ) ;
1615
1625
}
1616
1626
}
1617
1627
}
@@ -1855,19 +1865,21 @@ export function preloadCode(pathname) {
1855
1865
throw new Error ( 'Cannot call preloadCode(...) on the server' ) ;
1856
1866
}
1857
1867
1868
+ const url = new URL ( pathname , current . url ) ;
1869
+
1858
1870
if ( DEV ) {
1859
1871
if ( ! pathname . startsWith ( base ) ) {
1860
1872
throw new Error (
1861
1873
`pathnames passed to preloadCode must start with \`paths.base\` (i.e. "${ base } ${ pathname } " rather than "${ pathname } ")`
1862
1874
) ;
1863
1875
}
1864
1876
1865
- if ( ! routes . find ( ( route ) => route . exec ( get_url_path ( pathname ) ) ) ) {
1877
+ if ( ! routes . find ( ( route ) => route . exec ( get_url_path ( url ) ) ) ) {
1866
1878
throw new Error ( `'${ pathname } ' did not match any routes` ) ;
1867
1879
}
1868
1880
}
1869
1881
1870
- return _preload_code ( pathname ) ;
1882
+ return _preload_code ( url ) ;
1871
1883
}
1872
1884
1873
1885
/**
0 commit comments