Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add Page in NextJS Project

Tags:

next.js

hope all of you have a great day!

I want to ask something, i create new project using npx create-next-app@latest using typescript and tailwind as css, look like this:

enter image description here

then i got the stack folder tree like this:

enter image description here

Then the problem is, i got confused, previous project using nextJS the file tree is not like this, now i didn't have folder called Pages anymore, is this the new thing?

Then i realized that i can't create new page (ex: i want to create test page, previously i just create folder named test inside pages folder and create index.tsx file)

How can i create new page with this scheme?

like image 222
Haksatrya Bhaswara Avatar asked Sep 14 '25 21:09

Haksatrya Bhaswara


2 Answers

Inside app you can create folder else file name. folder name will work as part of url and file name words as end part or url.

structure : App>testcomponent>component1>index.js
url : ../testcomponent/component1/index.js

there could be multiple level of nesting in folder names to create nested routes.

For dynamic routes

structure : App>testcomponent>component1>[id].js
url : ../testcomponent/component1/index.js

you need to pass the id number at the end of URL to open that particular file as per requirement.

Same applies to folder.

Here id is just and example.

like image 154
Shah Vipul Avatar answered Sep 16 '25 16:09

Shah Vipul


Go inside app folder and create folder for a page for example if you want to create a page about you should create folder named about and inside about you should create page.tsx it will automatically detect the content inside page.tsx

example of creating routes

read more at https://nextjs.org/docs/app/building-your-application/routing/pages-and-layouts

like image 42
Kashif Nazeer Avatar answered Sep 16 '25 16:09

Kashif Nazeer