I'm building an app where I get topics you learn at school to make a page for each topic, and then for each topic I get the resources from the resources table. I'm using Flask on the BE. I want to use the topic id that I get by fetching the topic, and then put it back into the fetch request.
How do I do this given my current code below? I already have a flask route. Remember I am using the App router as recommended by next.js since version 13, and this code is currently 100% correct:
// /topic/[topicName]/page.tsx
import React from 'react';
// This import will be used for SEO optimisation
import { Metadata, ResolvingMetadata } from 'next';
import DOMPurify from 'isomorphic-dompurify';
interface Params {
topicName: string;
}
interface Topic {
id: string;
name: string;
latitude: number;
longitude: number;
description: string;
}
export async function generateStaticParams() {
const topics = await fetch(${process.env.NEXT_PUBLIC_API_BASE_URL}/topics).then(res => res.json())
return topics.map((topic: Topic) => ({
topicName: encodeURIComponent(topic.name),
}))
}
const TopicPage = async ({ params }: { params: Params }) => {
const { topicName } = params;
const decodedTopicName = decodeURIComponent(topicName);
const topic = await fetch(${process.env.NEXT_PUBLIC_API_BASE_URL}/topics/${decodedTopicName}).then(res => res.json())
// Sanitize the description HTML content
const sanitizedDescription = DOMPurify.sanitize(topic.description);
return (
// sidebar
<div className="absolute bottom-0 left-0 sm:left-0 sm:bottom-auto sm:top-0 sidenav w-full sm:w-2/5 md:w-1/3 xl:w-1/4 h-2/5 sm:h-full p-4 overflow-y-auto bg-white shadow-xl rounded-t-md">
<h1 className="text-xl font-bold">{decodedTopicName}</h1>
<div dangerouslySetInnerHTML={{ __html: sanitizedDescription }} />
{/* More content */}
</div>
);
};
export default TopicPage;