动态 ID 渲染在 Next.js 13.4.6 中不起作用。

huangapple go评论69阅读模式
英文:

Dynamic id rendering not working in nextjs 13.4.6

问题

我正在学习 Next.js... 在这个项目之前,我使用了动态 ID 渲染。
但是现在出现了一些错误。
Next.js 13.4.6 中动态 ID 渲染不起作用。
我找不到错误所在。
是因为我没有页面文件夹而是应用程序文件夹吗?
英文:

动态 ID 渲染在 Next.js 13.4.6 中不起作用。动态 ID 渲染在 Next.js 13.4.6 中不起作用。

i am learning next-js .. before this project i used the dynamic id rendering .
but now this throws some error
Dynamic Id rendering not working in next js 13.4.6.
i can't find the error .
is it because i dont have pages folder instead of app folder

答案1

得分: 1

由于您正在使用基于app文件夹的路由(这是NextJS 13中的新功能),而不是旧的基于page文件夹的路由,因此您需要创建一个动态文件夹名称路由。在您的情况下,它将是[user],并在其中添加page.js文件。

因此,您的目录结构将如下所示:

/project-name
├─ app/
│  ├─ [user]/
│  │  ├─ error.js
│  │  ├─ layout.js
│  │  ├─ page.js
│  ├─ error.js
│  ├─ layout.js
│  ├─ page.js

您的页面的主要逻辑将始终位于page.js文件中。要更详细地了解这一点,您可以查看NextJS文档上关于服务器组件路由的说明或观看这个Fireship视频

英文:

Since you are using the app folder-based routing (which is new in NextJS 13) instead of the older page folder-based routing, so you have to create a dynamic folder name route. In your case it will be [user] and inside that you will have to add page.js file.

So your directory structure will look like this:


/project-name
├─ app/
│  ├─ [user]/
│  │  ├─ error.js
│  │  ├─ layout.js
│  │  ├─ page.js
│  ├─ error.js
│  ├─ layout.js
│  ├─ page.js

Your main logic for the page will always reside in the page.js file. For more detailed understanding of this you can explore the NextJS documentation on server components routing or look at this Fireship video

huangapple
  • 本文由 发表于 2023年6月18日 18:06:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76499987.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定