Skip to content

g1t/apps/web/app/routes/not-found.tsx

24 lines884 bytesCodeBlame
1import { data } from "react-router";
2
3import type { Route } from "./+types/not-found";
4import { redirectIfRenamed } from "../lib/renamed.server";
5import { pagePath } from "../lib/workspace-nav";
6
7/**
8 * Any address no other route matches. Throwing the 404 from a route, rather
9 * than leaving the router to, means the root loader still runs, so someone
10 * signed in sees the page in their own sidebar and not the public frame.
11 *
12 * An address under a renamed workspace's old name, or under an alias, is
13 * sent to the workspace's name first, so deep links keep working the same
14 * as its pages do.
15 */
16export async function loader({ request }: Route.LoaderArgs) {
17 const first = pagePath(new URL(request.url).pathname).split("/")[1];
18 if (first) await redirectIfRenamed(request, first);
19 throw data(null, { status: 404 });
20}
21
22export default function NotFound() {
23 return null;
24}