Open GandharvJaggi opened 2 years ago
same bug here https://github.com/vercel/next.js/issues/41383
I am also seeing this bug, and its getting close to a year old for such a simple problem. Not sure why the other one was closed, but query params added to a URL don't end up being properly added to context when using a custom server. The preference here would be for the context object to reflect the standard interface for Node server contexts.
Verify canary release
Provide environment information
Operating System: Platform: darwin Arch: x64 Version: Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 Binaries: Node: 16.13.2 npm: 8.1.2 Yarn: N/A pnpm: N/A Relevant packages: next: 12.2.2 eslint-config-next: N/A react: 18.2.0 react-dom: 18.2.0
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
we are using custom express server for server side routing, and using the same for dynamic routes. The problem arises in the passing of query params from the server to the context of data fetching functions.
we have a file pages/news/[news].js and in the file we use getServerSideProps. the context of the function returns
context.params = {news: '[news]'}
Expected Behavior
it is supposed the return the dyanmic url param for http://localhost:3000/news/23572
context.params = {news: '23572'}
Link to reproduction
-
To Reproduce
create next app
create custom server
copy the example express server server.js and add
server.get('/news/:news', (req, res) => { const queryParams = { news: req.params.news }; const pagePath = '/news/[news]'; return app.render(req, res, pagePath, queryParams); });
in pages/news/[news].js
export const getServerSideProps = async (ctx) => { console.log({ query: ctx.query, params: ctx.params }); return {props: {}}; }