Skip to content

Commit

Permalink
fix initial spa render of 404 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkishi committed Feb 17, 2022
1 parent 08b1881 commit db16e00
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/kit/src/runtime/client/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,14 @@ export class Renderer {
);
if (result) return result;
}

if (info.initial) {
return await this._load_error({
status: 404,
error: new Error(`Not found: ${info.url.pathname}`),
url: info.url
});
}
}

/**
Expand Down
6 changes: 5 additions & 1 deletion packages/kit/src/runtime/client/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class Router {
renderer.router = this;

this.enabled = true;
this.initialized = false;

// make it possible to reset focus
document.body.setAttribute('tabindex', '-1');
Expand Down Expand Up @@ -252,6 +253,8 @@ export class Router {
);
}
});

this.initialized = true;
}

/**
Expand All @@ -274,7 +277,8 @@ export class Router {
id: url.pathname + url.search,
routes: this.routes.filter(([pattern]) => pattern.test(path)),
url,
path
path,
initial: !this.initialized
};
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/kit/src/runtime/client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export type NavigationInfo = {
routes: CSRRoute[];
url: URL;
path: string;
initial: boolean;
};

export type NavigationCandidate = {
Expand Down

0 comments on commit db16e00

Please sign in to comment.