page.js File & Nested Routing

A page.js is a component that contains a UI elements, which are displayed when you move to any route. Next.js 13 App Router automatically consider the page.js file when you move to any route and content of it is rendered on display. This file is not optional.

Nested Route is a route that is contained within another route. This allows you to create a hierarchy of routes, which can be useful for organizing your application’s content.

For example, you have created a cloths folder in a app directory and inside that folder you have created a men and women folder and inside both the folder you have created a page.js component. So if you want to open men cloths section you can access it by using http://localhost:3000/cloths/men and if you want to open women cloths section you can access it by using http://localhost:3000/cloths/women and the content written inside page.js will be displayed.

Next JS 13 App Router

Routing refers to the process of determining how an application responds to a client request to a particular endpoint or URL. When a user clicks a link, enters a URL in the browser, or performs some action that changes the current URL, the routing mechanism decides which content or component to display on the page.

In this article, we will learn about Next.js 13 App router. Routing is an important concept in building single-page applications (SPAs) and dynamic web applications where navigating between pages updates the content on the page without a full reload, providing a smoother and more seamless user experience.

Table of Content

  • Next.js 13 App Router Usage
  • page.js File & Nested Routing
  • layout.js File
  • error.js File
  • not-found.js
  • loading.js
  • Steps to use App Router in Next.js 13

Similar Reads

Next.js 13 App Router Usage

Next.js 13 App Router provides Hierarchical File Structure routing. which provides features such as shared layout, nested routing, loading states, error handling, 404 not found page, and many more....

page.js File & Nested Routing

A page.js is a component that contains a UI elements, which are displayed when you move to any route. Next.js 13 App Router automatically consider the page.js file when you move to any route and content of it is rendered on display. This file is not optional....

layout.js File

A layout.js file is a component that is shared between multiple page.js (UI). It allow you to create common shared structure for multiple pages. This file is not optional your Application should must have a one layout.js file in a root directory. Root directory layout file is used as a container for whole application. Root level layout files contains main html and body structure of an application and inside body tag you have to put all children components....

error.js File

A error.js file is a component that is displayed when any error is occurred. It is used to create a custom error page that is displayed to the user when an error occurs. error.js file will automatically wraps the page inside a React error boundary so whenever any error will occurs inside the folder where error.js file is placed, it will automatically replaces it with error.js file. This file is optional....

not-found.js

A not-found.js component that is displayed when user tries to enter wrong route that doesn’t exist in our website. By using it you can create a custom 404 Not Found Page. This file is optional....

loading.js

A loading.js component that is displayed during page transitions when content is being fetched from the server. If the content is already present in cache memory, such as when a user revisits a page they’ve previously loaded, the loader may not be displayed. This file is optional....

Steps to use App Router in Next.js 13

Step 1: Create Next.js App...

Contact Us