Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lernen File Based Routing in Next.js | Section
Üben
Projekte
Quiz & Herausforderungen
Quizze
Herausforderungen
/
Building Web Apps with Next.js

bookFile Based Routing in Next.js

Swipe um das Menü anzuzeigen

In traditional React applications, routing is something you configure manually using a library. You define paths, connect them to components, and maintain that configuration as your app grows.

In Next.js, routing works differently.

Next.js uses file-based routing, which means your folder and file structure automatically defines your application routes. You do not need to set up a router or write route configuration.

This approach makes routing simpler, more predictable, and easier to scale.

Example - Basic Routing Structure

Inside the app/ folder, each folder represents a route segment:

app/
  page.tsx
  about/
    page.tsx
  contact/
    page.tsx

What URLs These Create

  • app/page.tsx/;
  • app/about/page.tsx/about;
  • app/contact/page.tsx/contact.

Each page.tsx file defines what is displayed for that route.

Why File-Based Routing Is Useful

  • You do not need to configure routes manually;
  • The structure is easy to understand by looking at folders;
  • Adding new pages is fast and predictable;
  • It reduces boilerplate code compared to traditional routing setups.

How It Scales

As your app grows, you simply add more folders and pages:

app/
  blog/
    page.tsx
    post/
      page.tsx

This creates routes like:

  • /blog
  • /blog/post

The structure remains consistent even in larger applications.

question mark

How are routes defined in Next.js using the App Router?

Wählen Sie die richtige Antwort aus

War alles klar?

Wie können wir es verbessern?

Danke für Ihr Feedback!

Abschnitt 1. Kapitel 7

Fragen Sie AI

expand

Fragen Sie AI

ChatGPT

Fragen Sie alles oder probieren Sie eine der vorgeschlagenen Fragen, um unser Gespräch zu beginnen

Abschnitt 1. Kapitel 7
some-alt