/** * Catch-all route — handles both subpage listings and album detail pages. * * Single segment: * - If slug matches a subpage → render subpage album grid * - If slug matches a standalone album → render album detail * * Two segments: * - Treat as subpage-slug/album-slug → render album detail * with back-link to the subpage */ import Link from 'next/link'; import { immich } from '@/lib/immich'; import { notFound } from 'next/navigation'; import { PhotoGrid } from './PhotoGrid'; import { imageUrl, exifUrl } from '@/lib/urls'; // Render at request time — requires live Immich connection export const dynamic = 'force-dynamic'; interface PathPageProps { params: Promise<{ path: string[] }>; } export default async function PathPage({ params }: PathPageProps) { const { path } = await params; if (!path || path.length === 0) { notFound(); } // ── Two segments: subpage/album ────────────────────────────── if (path.length === 2) { const [subpageSlug, albumSlug] = path; const album = await immich.getAlbumBySlug(albumSlug, subpageSlug); if (!album) { notFound(); } // Get subpage name for the back link const subpageData = await immich.getSubpageAlbums(subpageSlug); const subpageName = subpageData?.subpage.name ?? subpageSlug; const images = album.assets.filter((asset) => asset.type === 'IMAGE'); return ( <>
Back to {subpageName}

{album.albumName}

{images.length} {images.length === 1 ? 'photo' : 'photos'} {album.description && ` · ${album.description}`}

({ id: a.id, thumbUrl: imageUrl(a.id, 'preview'), previewUrl: imageUrl(a.id, 'preview'), originalUrl: imageUrl(a.id, 'original'), exifUrl: exifUrl(a.id), }))} albumId={album.id} /> ); } // ── Single segment: subpage or standalone album ────────────── const slug = path[0]; // Check if it's a subpage if (immich.isSubpageSlug(slug)) { const result = await immich.getSubpageAlbums(slug); if (!result || result.albums.length === 0) { notFound(); } const { albums } = result; return (
{albums.map((album) => ( {album.albumThumbnailAssetId ? ( {album.albumName} ) : (
)}
{album.albumName} {album.assetCount} {album.assetCount === 1 ? 'photo' : 'photos'}
))}
); } // Otherwise treat as a standalone album slug const album = await immich.getAlbumBySlug(slug); if (!album) { notFound(); } const images = album.assets.filter((asset) => asset.type === 'IMAGE'); return ( <>
Back to Gallery

{album.albumName}

{images.length} {images.length === 1 ? 'photo' : 'photos'} {album.description && ` · ${album.description}`}

({ id: a.id, thumbUrl: imageUrl(a.id, 'preview'), previewUrl: imageUrl(a.id, 'preview'), originalUrl: imageUrl(a.id, 'original'), exifUrl: exifUrl(a.id), }))} albumId={album.id} /> ); }