Skip to content

Commit eaba628

Browse files
Rich-Harrismrkishi
andauthored
fix initial spa render of 404 errors (#3980)
Co-authored-by: mrkishi <[email protected]>
1 parent 08b1881 commit eaba628

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,14 @@ export class Renderer {
496496
);
497497
if (result) return result;
498498
}
499+
500+
if (info.initial) {
501+
return await this._load_error({
502+
status: 404,
503+
error: new Error(`Not found: ${info.url.pathname}`),
504+
url: info.url
505+
});
506+
}
499507
}
500508

501509
/**

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export class Router {
5151
renderer.router = this;
5252

5353
this.enabled = true;
54+
this.initialized = false;
5455

5556
// make it possible to reset focus
5657
document.body.setAttribute('tabindex', '-1');
@@ -252,6 +253,8 @@ export class Router {
252253
);
253254
}
254255
});
256+
257+
this.initialized = true;
255258
}
256259

257260
/**
@@ -274,7 +277,8 @@ export class Router {
274277
id: url.pathname + url.search,
275278
routes: this.routes.filter(([pattern]) => pattern.test(path)),
276279
url,
277-
path
280+
path,
281+
initial: !this.initialized
278282
};
279283
}
280284
}

packages/kit/src/runtime/client/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export type NavigationInfo = {
55
routes: CSRRoute[];
66
url: URL;
77
path: string;
8+
initial: boolean;
89
};
910

1011
export type NavigationCandidate = {

0 commit comments

Comments
 (0)