You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/01-getting-started/01-installation.mdx
+62-4Lines changed: 62 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,9 +69,15 @@ These scripts refer to the different stages of developing an application:
69
69
-`start`: runs [`next start`](/docs/app/api-reference/next-cli#production) to start a Next.js production server.
70
70
-`lint`: runs [`next lint`](/docs/app/api-reference/next-cli#lint) to set up Next.js' built-in ESLint configuration.
71
71
72
-
### Create the `app` folder
72
+
### Creating directories
73
73
74
-
Next, create an `app` folder and add a `layout.tsx` and `page.tsx` file. These will be rendered when the user visits the root of your application.
74
+
Next.js uses file-system routing, which means how you structure your files determines the routes in your application.
75
+
76
+
#### The `app` directory
77
+
78
+
For new applications, we recommend using the App Router. This router allows you to use React's latest features and is an evolution of the Pages Router based on community feedback.
79
+
80
+
To use the `app` router, create an `app/` folder, then add a `layout.tsx` and `page.tsx` file. These will be rendered when the user visits the root of your application (`/`).
75
81
76
82
<Image
77
83
alt="App Folder Structure"
@@ -123,12 +129,64 @@ export default function Page() {
123
129
124
130
> **Good to know**: If you forget to create `layout.tsx`, Next.js will automatically create this file for you when running the development server with `next dev`.
125
131
126
-
### Create the `public` folder
132
+
Learn more about [using the App Router](/docs/app/building-your-application/routing/defining-routes).
133
+
134
+
#### The `pages` directory (optional)
135
+
136
+
If you prefer to use the Pages Router instead of the App Router, you can create a `pages/` directory at the root of your project.
137
+
138
+
Then, add an `index.tsx` file inside your `pages` folder. This will be your home page (`/`):
139
+
140
+
```tsx filename="pages/index.tsx" switcher
141
+
exportdefaultfunction Page() {
142
+
return <h1>Hello, Next.js!</h1>
143
+
}
144
+
```
145
+
146
+
Next, add an `_app.tsx` file inside `pages/` to define the global layout. Learn more about the [custom App file](/docs/pages/building-your-application/routing/custom-app)).
Finally, add a `_document.tsx` file inside `pages/` to control the initial response from the server. Learn more about the [custom Document file](/docs/pages/building-your-application/routing/custom-document).
Learn more about [using the Pages Router](/docs/pages/building-your-application/routing/pages-and-layouts).
181
+
182
+
> **Good to know**: Although you can use both routers in the same project, routes in `app` will be prioritized over `pages`. We recommend using only one router in your new project to avoid confusion.
183
+
184
+
### The `public` folder (optional)
127
185
128
186
You can optionally create a `public` folder to store static assets such as images, fonts, etc. Files inside `public` directory can then be referenced by your code starting from the base URL (`/`).
129
187
130
188
## Run the Development Server
131
189
132
190
1. Run `npm run dev` to start the development server.
133
191
2. Visit `http://localhost:3000` to view your application.
134
-
3. Edit `app/layout.tsx` or `app/page.tsx`and save to see the updated result in your browser.
192
+
3. Edit `app/layout.tsx`(or `pages/index.tsx`) file and save it to see the updated result in your browser.
0 commit comments