To fetch data based on the dynamic route number, you can use a Client Component with useSWR for data fetching. Here's an example of how you can modify your code:
- First, import
useSWR:
import useSWR from 'swr';
- Create a fetcher function:
const fetcher = (url: string) => fetch(url).then((r) => r.json());
- Use
useSWR to fetch data based on the ship.imo:
export default function Page({ params }: { params: { ship: number } }) {
const { data, error } = useSWR(
`https://your-api-url/ship/${params.ship}`,
fetcher,
);
if (error) return 'Failed to load';
if (!data) return 'Loading...';
return <YourComponent data={data} />;
}
Replace https://your-api-url/ship/ with the actual API URL you want to fetch data from.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: