| 1 | import { data } from "react-router"; |
| 2 | |
| 3 | import type { Route } from "./+types/not-found"; |
| 4 | import { redirectIfRenamed } from "../lib/renamed.server"; |
| 5 | import { 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 | */ |
| 16 | export 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 | |
| 22 | export default function NotFound() { |
| 23 | return null; |
| 24 | } |