Next.js Discord

Discord Forum

How can I create a route without rendering to end user?

Unanswered
Indian oil sardine posted this in #help-forum
Open in Discord
Indian oil sardineOP
Hi guys, I'm creating a new functionality where I need to create a PDF from a react component. I don't want to show the route to the end user. The PDF would generate when you click an 'Export to PDF' button in another page. The problem is I don't know how to call my server component without rendering it and passing necessary props.

I already tried to convert into a client component so I could call via router.push method from 'next/navigation' and get props via useSearchParams(). But I'm in a deadlock: if I turn my component into a client component, I need to wrap all data fetch into a React.useEffect and set flags to show result when it is read'y. But this is causing bugs in my code (like 'can not read properties of undefined' even when I set to read after attributing value to variables). If I keep as server component, I don't know how to pass props because I can not extract via params in URL. I don't know what to do.

Any help will be greatly appreciated.

0 Replies