#how to pass data from expressjs route to nextjs file
17 messages · Page 1 of 1 (latest)
Can you elaborate?
Ok so while using expressjs for server I could pass data on a user request to my ejs template and the html page was rendered in the server can we do something like this with nextjs too ( I'm thinking to use expressjs and nextjs together)
You can do that with server component.
If you run a fetch in server component (or any logic you need to run before rendering it), it will be returned in a variable which you can pass to child components
And what if I need to pass something from the routes file like the user data at the time of request
Not sure what you mean by routes file
But any data is gathered in the page.tsx file and passed down to components
you call the function to get the userData in server component. It will be run in the server, at the time of request
if ure using the /app folder, and using pages.jsx, it wont go through route.js
so if you are requesting for a page in url:3000/helloworld it would go through /app/helloworld
and check if there is pages.jsx. If not it would then check for route.js
You can't have both route.js and pages.jsx in the same route...
yeah in express routes we were used to handle the GET request, do some app logic, then render the pages..
im explaining that in nextjs, the page rendering route is different from traditional GET route handler...
so if you want to handle GET request to perform page rendering, you have to use the page.jsx
but if you only want to handle GET request to return a data, use the route.js
you can't use both at the same route/filepath
i hope that make sense
If we use post or put it would definetly not for rendering page so thats out of the question