hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import { ApiError } from "@/api/client"; |
| 2 | |
| 3 | /** A read that failed because the record is not there (deleted, or a bad link). */ |
| 4 | export function isNotFoundError(err: unknown): boolean { |
| 5 | return err instanceof ApiError && err.status === 404; |
| 6 | } |
| 7 | |
| 8 | // Detail routes whose parent path is not a list page of their own. |
| 9 | const LIST_OVERRIDES: Record<string, string> = { |
| 10 | "/instances": "/courses", |
| 11 | }; |
| 12 | |
| 13 | /** |
| 14 | * The list a detail URL belongs to: its path minus the last segment |
| 15 | * (`/management/classes/abc` → `/management/classes`), when that is a route |
| 16 | * the app has; otherwise the home page. |
| 17 | */ |
| 18 | export function listPathFor(pathname: string, hasRoute: (path: string) => boolean): string { |
| 19 | const trimmed = pathname.replace(/\/+$/, ""); |
| 20 | const parent = trimmed.slice(0, trimmed.lastIndexOf("/")); |
| 21 | if (!parent) return "/"; |
| 22 | const target = LIST_OVERRIDES[parent] ?? parent; |
| 23 | return hasRoute(target) ? target : "/"; |
| 24 | } |