Fix router type

This commit is contained in:
grove5_admin committed 2026-04-30 22:51:11 -07:00
1 parent 6a77277357
commit 8233bfd33a
2 files changed
+9 -3

No files matched your search

+6
View File
@@ -3,6 +3,7 @@ import { writable, type Writable } from 'svelte/store';
export type Route = export type Route =
| { page: 'overview' } | { page: 'overview' }
| { page: 'reference' } | { page: 'reference' }
| { page: 'referenceDetail'; type: 'species' | 'contaminant'; id: string }
| { page: 'bag'; bagId: string } | { page: 'bag'; bagId: string }
| { page: 'onboarding' }; | { page: 'onboarding' };
@@ -14,6 +15,9 @@ function parseHash(hash: string): Route {
switch (page) { switch (page) {
case 'reference': case 'reference':
if (rest[1] && (rest[0] === 'species' || rest[0] === 'contaminant')) {
return { page: 'referenceDetail', type: rest[0], id: rest[1] };
}
return { page: 'reference' }; return { page: 'reference' };
case 'bag': case 'bag':
return rest[0] ? { page: 'bag', bagId: rest[0] } : { page: 'overview' }; return rest[0] ? { page: 'bag', bagId: rest[0] } : { page: 'overview' };
@@ -30,6 +34,8 @@ function routeToHash(route: Route): string {
return ''; return '';
case 'reference': case 'reference':
return '#reference'; return '#reference';
case 'referenceDetail':
return `#reference/${route.type}/${route.id}`;
case 'bag': case 'bag':
return `#bag/${route.bagId}`; return `#bag/${route.bagId}`;
case 'onboarding': case 'onboarding':
+3 -3
View File
@@ -15,10 +15,10 @@
interface Props { interface Props {
onBack: () => void; onBack: () => void;
initialDetailType: 'species' | 'contaminant' | null; initialDetailType?: 'species' | 'contaminant' | null;
initialDetailId: string | null; initialDetailId?: string | null;
} }
const { onBack, initialDetailType, initialDetailId }: Props = $props(); const { onBack, initialDetailType = null, initialDetailId = null }: Props = $props();
// ── Tab state ───────────────────────────────────────────────────── // ── Tab state ─────────────────────────────────────────────────────
type Tab = 'species' | 'contaminants'; type Tab = 'species' | 'contaminants';