next.js: Not getting `url.query` in custom parametrised server route

Expected behavior

Got to detail/post-id and see rendered post detail. (server should wait until data is fetched and then return post detail)

Actual behavior

Go to detail/post-id and see spinner then see post detail. (server does not wait until data is fetched and renders spinner client then renders post detail)

image

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 19 (4 by maintainers)

Most upvoted comments

Thank you @developer239 !

Your solution was ok, but the url should be placed on composedInitialProps after the

if (ComposedComponent.getInitialProps) {
  composedInitialProps = await ComposedComponent.getInitialProps(ctx)
}

otherwise it would be replaced.

the thing there is that Next only knows the page /detail, /detail?id=cjdg4ro6z2zfb0154l6jubt89 is the same page but with a query param but detail/cjdg4ro6z2zfb0154l6jubt89 is a different page for Next.

Basically, you need to send more parameters to <Link> like here or use a lib like next-routes

Oh, I’m sorry for not being clear. The issue is that ComposedComponent is only getting the props inside { …composedInitialProps } and unless you have url there you’re actually not sending url to the component during the execution of getDataFromTree that happens before getInitialProps ends.

Hello!, some questions:

Are you sending url in props ? (I can’t see it anywhere) Does it happens always or only on client side navigation ?