Next.js Discord

Discord Forum

URL is malformed

Answered
ᵗʰᵉ Nexus posted this in #help-forum
Open in Discord
Can't I use 'fetch' without the 'baseURL' in dynamic routes? I have something like this:
products/
[id]/
page.tsx
// page.tsx
export default async function Product({ params }: { params: { id: string } }) {
    const res = await fetch(`/api/products?id=${params.id}`, {
        cache: "force-cache",
    });
        ...


Why doesn't it work? It works fine in other server components! It just doesn't work in the server component of the dynamic route.

If I really need to set a baseURL, what would be the best way to do that? I am hosting on Vercel and testing locally.
Answered by riský
are you fetching your own api in server component, if so read: https://nextjs-faq.com/fetch-api-in-rsc
View full answer

2 Replies

are you fetching your own api in server component, if so read: https://nextjs-faq.com/fetch-api-in-rsc
Answer