ant-design / ant-design-examples

Use antd in create-next-app
67 stars 38 forks source link

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

Closed Sherryme closed 1 year ago

Sherryme commented 1 year ago

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

直接await fetch的话,在老版本 Next.js 上会造成客户端也产生请求并无限重发,在新版本 Next.js 上会报错:https://github.com/vercel/next.js/issues/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: https://github.com/vercel/next.js/issues/42180

MadCcc commented 1 year ago

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