Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Creating a Common Layout | Pages and Layouts
course content

Зміст курсу

Next.js 14

Creating a Common LayoutCreating a Common Layout

Let's design a layout for the entire app. In this scenario, we'll create a component that aids in navigating through the app's pages and also provides the option to log out (more on authorization in upcoming chapters).

Most of the components have already been created for you, so you can focus solely on exploring the features of Next.js. If you are unsure about the origin of a particular UI element, it is recommended that you inspect all the components on the current page and navigate through different sections to break them down and understand them better.

Back to the Project

Now, let's generate a layout.tsx for the dashboard. Within the /dashboard folder, introduce a new file named layout.tsx and insert the following code:

app/dashboard/layout.tsx

In this code, a few key actions are happening. Let's take a closer look:

  • We are bringing in the <SideNav /> component and making it part of our layout. Any components we import here become part of the overall page design;
  • The <Layout /> component has a children prop. This "child" can be either a page or another layout. Specifically, the pages located in /dashboard will be automatically placed within a <Layout />.

Now, attempt to follow the link http://localhost:3000/dashboard and navigate between the dashboard and the invoices page.

This is where the beauty of Next.js shines through. The Layout component remains unaltered and consistently available to the user, while other pages dynamically update as they are viewed.

Все було зрозуміло?

Секція 3. Розділ 3
course content

Зміст курсу

Next.js 14

Creating a Common LayoutCreating a Common Layout

Let's design a layout for the entire app. In this scenario, we'll create a component that aids in navigating through the app's pages and also provides the option to log out (more on authorization in upcoming chapters).

Most of the components have already been created for you, so you can focus solely on exploring the features of Next.js. If you are unsure about the origin of a particular UI element, it is recommended that you inspect all the components on the current page and navigate through different sections to break them down and understand them better.

Back to the Project

Now, let's generate a layout.tsx for the dashboard. Within the /dashboard folder, introduce a new file named layout.tsx and insert the following code:

app/dashboard/layout.tsx

In this code, a few key actions are happening. Let's take a closer look:

  • We are bringing in the <SideNav /> component and making it part of our layout. Any components we import here become part of the overall page design;
  • The <Layout /> component has a children prop. This "child" can be either a page or another layout. Specifically, the pages located in /dashboard will be automatically placed within a <Layout />.

Now, attempt to follow the link http://localhost:3000/dashboard and navigate between the dashboard and the invoices page.

This is where the beauty of Next.js shines through. The Layout component remains unaltered and consistently available to the user, while other pages dynamically update as they are viewed.

Все було зрозуміло?

Секція 3. Розділ 3
some-alt