forked from mirrors/pronouns.cc
feat: redirect /[username] to /@[username] if no page matches
This commit is contained in:
parent
56c0d40a11
commit
c60429d884
2 changed files with 20 additions and 0 deletions
19
frontend/src/routes/[username]/+page.server.ts
Normal file
19
frontend/src/routes/[username]/+page.server.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import { ErrorCode, type APIError, type User } from "$lib/api/entities";
|
||||||
|
import { apiFetch } from "$lib/api/fetch";
|
||||||
|
import { error, redirect } from "@sveltejs/kit";
|
||||||
|
|
||||||
|
export const load = async ({ params }) => {
|
||||||
|
try {
|
||||||
|
const resp = await apiFetch<User>(`/users/${params.username}`, {
|
||||||
|
method: "GET",
|
||||||
|
});
|
||||||
|
|
||||||
|
throw redirect(303, `/@${resp.name}`);
|
||||||
|
} catch (e) {
|
||||||
|
if ((e as APIError).code === ErrorCode.UserNotFound) {
|
||||||
|
throw error(404, (e as APIError).message);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
};
|
1
frontend/src/routes/[username]/+page.svelte
Normal file
1
frontend/src/routes/[username]/+page.svelte
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<h1>Page not found</h1>
|
Loading…
Reference in a new issue