Closed Sherryme closed 1 year ago
正如标题所问,当我使用 app router 时,我如果要使用类似Layout.Footer的子组件,就需要在页面添加use client,但是这时我该如何在服务端获取数据并完成 ssr ?
Layout.Footer
use client
直接await fetch的话,在老版本 Next.js 上会造成客户端也产生请求并无限重发,在新版本 Next.js 上会报错:https://github.com/vercel/next.js/issues/42180
await fetch
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
你可以直接从路径引入 Footer,这样就不需要添加 use client 了
正如标题所问,当我使用 app router 时,我如果要使用类似
Layout.Footer
的子组件,就需要在页面添加use client
,但是这时我该如何在服务端获取数据并完成 ssr ?直接
await fetch
的话,在老版本 Next.js 上会造成客户端也产生请求并无限重发,在新版本 Next.js 上会报错:https://github.com/vercel/next.js/issues/42180As the title asks, when I use app router, I need to add
use client
to the page if I want to use a subcomponent likeLayout.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