Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to fetch data on server if add use client when use next.js app router #24

Closed
Sherryme opened this issue Jul 31, 2023 · 1 comment
Closed

Comments

@Sherryme
Copy link

正如标题所问,当我使用 app router 时,我如果要使用类似Layout.Footer的子组件,就需要在页面添加use client,但是这时我该如何在服务端获取数据并完成 ssr ?

直接await fetch的话,在老版本 Next.js 上会造成客户端也产生请求并无限重发,在新版本 Next.js 上会报错:vercel/next.js#42180


As the title asks, when I use app router, I need to add use client to the page if I want to use a subcomponent like Layout.Footer, but then how do I get the data on the server side and complete the ssr?

Just await fetch will result in an infinite client request on older versions of Next.js and an error on newer versions of Next.js: vercel/next.js#42180

@MadCcc
Copy link
Member

MadCcc commented Nov 3, 2023

你可以直接从路径引入 Footer,这样就不需要添加 use client

@MadCcc MadCcc closed this as completed Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants