@@ -426,9 +426,15 @@ async function _preload_data(intent) {
426
426
return load_cache . promise ;
427
427
}
428
428
429
- /** @param {URL } url */
429
+ /**
430
+ * @param {URL } url
431
+ * @returns {Promise<void> }
432
+ */
430
433
async function _preload_code ( url ) {
431
- const route = routes . find ( ( route ) => route . exec ( get_url_path ( url ) ) ) ;
434
+ const rerouted = get_rerouted_url ( url ) ;
435
+ if ( ! rerouted ) return ;
436
+
437
+ const route = routes . find ( ( route ) => route . exec ( get_url_path ( rerouted ) ) ) ;
432
438
433
439
if ( route ) {
434
440
await Promise . all ( [ ...route . layouts , route . leaf ] . map ( ( load ) => load ?. [ 1 ] ( ) ) ) ;
@@ -1189,16 +1195,11 @@ async function load_root_error_page({ status, error, url, route }) {
1189
1195
}
1190
1196
1191
1197
/**
1192
- * Resolve the full info (which route, params, etc.) for a client-side navigation from the URL,
1193
- * taking the reroute hook into account. If this isn't a client-side-navigation (or the URL is undefined),
1194
- * returns undefined.
1195
- * @param {URL | undefined } url
1196
- * @param {boolean } invalidating
1198
+ * Resolve the relative rerouted URL for a client-side navigation
1199
+ * @param {URL } url
1200
+ * @returns {URL | undefined }
1197
1201
*/
1198
- function get_navigation_intent ( url , invalidating ) {
1199
- if ( ! url ) return ;
1200
- if ( is_external_url ( url , base , app . hash ) ) return ;
1201
-
1202
+ function get_rerouted_url ( url ) {
1202
1203
// reroute could alter the given URL, so we pass a copy
1203
1204
let rerouted ;
1204
1205
try {
@@ -1225,9 +1226,26 @@ function get_navigation_intent(url, invalidating) {
1225
1226
}
1226
1227
1227
1228
// fall back to native navigation
1228
- return undefined ;
1229
+ return ;
1229
1230
}
1230
1231
1232
+ return rerouted ;
1233
+ }
1234
+
1235
+ /**
1236
+ * Resolve the full info (which route, params, etc.) for a client-side navigation from the URL,
1237
+ * taking the reroute hook into account. If this isn't a client-side-navigation (or the URL is undefined),
1238
+ * returns undefined.
1239
+ * @param {URL | undefined } url
1240
+ * @param {boolean } invalidating
1241
+ */
1242
+ function get_navigation_intent ( url , invalidating ) {
1243
+ if ( ! url ) return ;
1244
+ if ( is_external_url ( url , base , app . hash ) ) return ;
1245
+
1246
+ const rerouted = get_rerouted_url ( url ) ;
1247
+ if ( ! rerouted ) return ;
1248
+
1231
1249
const path = get_url_path ( rerouted ) ;
1232
1250
1233
1251
for ( const route of routes ) {
@@ -1942,13 +1960,20 @@ export function preloadCode(pathname) {
1942
1960
const url = new URL ( pathname , current . url ) ;
1943
1961
1944
1962
if ( DEV ) {
1963
+ if ( ! pathname . startsWith ( '/' ) ) {
1964
+ throw new Error (
1965
+ 'argument passed to preloadCode must be a pathname (i.e. "/about" rather than "http://example.com/about"'
1966
+ ) ;
1967
+ }
1968
+
1945
1969
if ( ! pathname . startsWith ( base ) ) {
1946
1970
throw new Error (
1947
- `pathnames passed to preloadCode must start with \`paths.base\` (i.e. "${ base } ${ pathname } " rather than "${ pathname } ")`
1971
+ `pathname passed to preloadCode must start with \`paths.base\` (i.e. "${ base } ${ pathname } " rather than "${ pathname } ")`
1948
1972
) ;
1949
1973
}
1950
1974
1951
- if ( ! routes . find ( ( route ) => route . exec ( get_url_path ( url ) ) ) ) {
1975
+ const rerouted = get_rerouted_url ( url ) ;
1976
+ if ( ! rerouted || ! routes . find ( ( route ) => route . exec ( get_url_path ( rerouted ) ) ) ) {
1952
1977
throw new Error ( `'${ pathname } ' did not match any routes` ) ;
1953
1978
}
1954
1979
}
0 commit comments