Fix router type
This commit is contained in:
1 parent
6a77277357
commit
8233bfd33a
2 files changed
+9
-3
No files matched your search
@@ -3,6 +3,7 @@ import { writable, type Writable } from 'svelte/store';
|
||||
export type Route =
|
||||
| { page: 'overview' }
|
||||
| { page: 'reference' }
|
||||
| { page: 'referenceDetail'; type: 'species' | 'contaminant'; id: string }
|
||||
| { page: 'bag'; bagId: string }
|
||||
| { page: 'onboarding' };
|
||||
|
||||
@@ -14,6 +15,9 @@ function parseHash(hash: string): Route {
|
||||
|
||||
switch (page) {
|
||||
case 'reference':
|
||||
if (rest[1] && (rest[0] === 'species' || rest[0] === 'contaminant')) {
|
||||
return { page: 'referenceDetail', type: rest[0], id: rest[1] };
|
||||
}
|
||||
return { page: 'reference' };
|
||||
case 'bag':
|
||||
return rest[0] ? { page: 'bag', bagId: rest[0] } : { page: 'overview' };
|
||||
@@ -30,6 +34,8 @@ function routeToHash(route: Route): string {
|
||||
return '';
|
||||
case 'reference':
|
||||
return '#reference';
|
||||
case 'referenceDetail':
|
||||
return `#reference/${route.type}/${route.id}`;
|
||||
case 'bag':
|
||||
return `#bag/${route.bagId}`;
|
||||
case 'onboarding':
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
|
||||
interface Props {
|
||||
onBack: () => void;
|
||||
initialDetailType: 'species' | 'contaminant' | null;
|
||||
initialDetailId: string | null;
|
||||
initialDetailType?: 'species' | 'contaminant' | null;
|
||||
initialDetailId?: string | null;
|
||||
}
|
||||
const { onBack, initialDetailType, initialDetailId }: Props = $props();
|
||||
const { onBack, initialDetailType = null, initialDetailId = null }: Props = $props();
|
||||
|
||||
// ── Tab state ─────────────────────────────────────────────────────
|
||||
type Tab = 'species' | 'contaminants';
|
||||
|
||||
Reference in new issue
Block a user