Next.js Discord

Discord Forum

how to render component from nextjs response api

Unanswered
Levriero Sardo posted this in #help-forum
Open in Discord
Levriero SardoOP
how do I get a response or render a react component from the nextjs api, so for example I create a page.tsx component in the world/ folder, I want to render the contents of the page.tsx from the nextjs api where the output is html, to be used as a webview.

2 Replies

Levriero SardoOP
how do I get a response or render a react component from the nextjs api, so for example I create a page.tsx component in the world/ folder, I want to render the contents of the page.tsx from the nextjs api where the output is html, to be used as a webview.
@Levriero Sardo how do I get a response or render a react component from the nextjs api, so for example I create a page.tsx component in the world/ folder, I want to render the contents of the page.tsx from the nextjs api where the output is html, to be used as a webview.
impossible*, you need to use page.tsx instead of route.ts to render a page. you can use it under the api directory like app/api/anything/page.tsx no problem, but the page.tsx part is required.

* technically you can render a component to string and use that string in the route.ts response, but that is not the same as rendering a proper page.