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:
pages
src/app
dashboard.tsx
http://localhost:3000/dashboard
404 | This page could not be found.
why??
2
The root file of a directory is index.tsx
index.tsx
Edit
As pointed out by another answer, you are using Next 13 and the app folder feature.
app
The page you are aiming to create should be app/dashboard/index.tsx
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)
pages/dashboard/index.tsx
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 page.tsx = file, the page content, basically what you have in dashboard.tsx put it in this file
dashboard
page.tsx
You can check for differences here https://blog.logrocket.com/next-js-13-app-directory/#page-directory-vs-app-directory
Click here to cancel reply.
2
Answers
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)It seems you are using app directory feature of NextJS 13. To make
http://localhost:3000/dashboard
work the file structure should beapp/dashboard/page.tsx
dashboard
= a folderpage.tsx
= file, the page content, basically what you have in dashboard.tsx put it in this fileYou can check for differences here https://blog.logrocket.com/next-js-13-app-directory/#page-directory-vs-app-directory