添加新页面

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

Adding new pages

问题

我是新手使用Next.js,我正在添加一个新页面,我只是在src/app文件夹下创建了一个名为pages的文件夹,然后我添加了一个名为dashboard.tsx的文件,但是当我尝试访问http://localhost:3000/dashboard时,我遇到了这个问题:

404 | 无法找到此页面。

为什么?

英文:

I'm new with Next js, and I'm adding a new page, I just create a folder pages inside of src/app, then I add file dashboard.tsx but when I try to go to http://localhost:3000/dashboard I have this issue:

404 | This page could not be found.

why??

添加新页面

答案1

得分: 3

看起来你正在使用NextJS 13的应用程序目录功能。为了使http://localhost:3000/dashboard工作,文件结构应该如下:

app/dashboard/page.tsx

dashboard = 一个文件夹
page.tsx = 文件,页面内容,基本上是你在dashboard.tsx中的内容,请将其放入此文件中。

你可以在这里查看差异:https://blog.logrocket.com/next-js-13-app-directory/#page-directory-vs-app-directory

英文:

It seems you are using app directory feature of NextJS 13. To make http://localhost:3000/dashboard work the file structure should be

app/dashboard/page.tsx

dashboard = a folder <br />
page.tsx = file, the page content, basically what you have in dashboard.tsx put it in this file

You can check for differences here https://blog.logrocket.com/next-js-13-app-directory/#page-directory-vs-app-directory

答案2

得分: 0

目录的根文件是 index.tsx

编辑

正如另一个答案所指出的,您正在使用 Next 13 和 app 文件夹功能。

您打算创建的页面应该是 app/dashboard/index.tsx

(而不是之前提到的 pages/dashboard/index.tsx — 但如果您使用的是 Next 13 之前的版本,或者选择不使用 app 文件夹,则可以使用之前提到的方式)

英文:

The root file of a directory is index.tsx

Edit

As pointed out by another answer, you are using Next 13 and the app folder feature.

The page you are aiming to create should be app/dashboard/index.tsx

(not as previously mentioned pages/dashboard/index.tsx — which however would apply if you are pre-Next 13 or are opting out of the app folder)

huangapple
  • 本文由 发表于 2023年6月22日 10:08:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76528195.html
匿名

发表评论

匿名网友

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

确定