Skip to content

Commit 0bd072a

Browse files
committed
fall back to full page navigation for unmatched routes - closes #3935
1 parent 7c568ba commit 0bd072a

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

packages/kit/src/runtime/app/navigation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ async function invalidate_(resource) {
4545
/**
4646
* @type {import('$app/navigation').prefetch}
4747
*/
48-
function prefetch_(href) {
49-
return router.prefetch(new URL(href, get_base_uri(document)));
48+
async function prefetch_(href) {
49+
await router.prefetch(new URL(href, get_base_uri(document)));
5050
}
5151

5252
/**

packages/kit/src/runtime/client/renderer.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class Renderer {
149149
/** @type {Map<string, import('./types').NavigationResult>} */
150150
this.cache = new Map();
151151

152-
/** @type {{id: string | null, promise: Promise<import('./types').NavigationResult> | null}} */
152+
/** @type {{id: string | null, promise: Promise<import('./types').NavigationResult | undefined> | null}} */
153153
this.loading = {
154154
id: null,
155155
promise: null
@@ -316,6 +316,11 @@ export class Renderer {
316316
const token = (this.token = {});
317317
let navigation_result = await this._get_navigation_result(info, no_cache);
318318

319+
if (!navigation_result) {
320+
location.href = info.url.href;
321+
return;
322+
}
323+
319324
// abort if user navigated during update
320325
if (token !== this.token) return;
321326

@@ -407,7 +412,7 @@ export class Renderer {
407412

408413
/**
409414
* @param {import('./types').NavigationInfo} info
410-
* @returns {Promise<import('./types').NavigationResult>}
415+
* @returns {Promise<import('./types').NavigationResult | undefined>}
411416
*/
412417
load(info) {
413418
this.loading.promise = this._get_navigation_result(info, false);
@@ -459,7 +464,7 @@ export class Renderer {
459464
/**
460465
* @param {import('./types').NavigationInfo} info
461466
* @param {boolean} no_cache
462-
* @returns {Promise<import('./types').NavigationResult>}
467+
* @returns {Promise<import('./types').NavigationResult | undefined>}
463468
*/
464469
async _get_navigation_result(info, no_cache) {
465470
if (this.loading.id === info.id && this.loading.promise) {
@@ -491,12 +496,6 @@ export class Renderer {
491496
);
492497
if (result) return result;
493498
}
494-
495-
return await this._load_error({
496-
status: 404,
497-
error: new Error(`Not found: ${info.url.pathname}`),
498-
url: info.url
499-
});
500499
}
501500

502501
/**

packages/kit/src/runtime/client/router.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export class Router {
324324

325325
/**
326326
* @param {URL} url
327-
* @returns {Promise<import('./types').NavigationResult>}
327+
* @returns {Promise<import('./types').NavigationResult | undefined>}
328328
*/
329329
async prefetch(url) {
330330
const info = this.parse(url);

0 commit comments

Comments
 (0)