Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Routing in Next.js determines which UI appears at each URL. For new applications, use the App Router in the app directory: folders become URL segments, page.tsx files expose pages, and conventions such as layouts and dynamic folders handle shared UI and data-driven paths. The older Pages Router remains supported for existing applications.

This guide uses current Next.js 16-style App Router examples, including asynchronous params and the newer proxy.ts naming. Older Next.js projects may use synchronous-looking parameter examples and call request interception “Middleware,” so always check the documentation for the version your project uses.

Key takeaways

  • The App Router maps app/page.tsx to / and app/about/page.tsx to /about without a central route-registration file.
  • Use <Link> for ordinary internal navigation, and reserve useRouter() for navigation triggered by code or a user action.
  • Dynamic folders such as [slug], [...parts], and [[...parts]] read one, many, or optionally many URL segments.
  • App Router pages use next/navigation, while Pages Router components use next/router; mixing those APIs is a common source of errors.
  • Static hosting supports only a limited subset of Next.js behavior, while a Node.js deployment supports all Next.js features according to the official deployment documentation.

What does routing mean in Next.js?

Routing determines which UI Next.js renders for a requested URL. A route such as /about renders an About page, /blog renders a blog index, and /blog/hello can render the blog post whose slug is hello.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Next.js uses file-system routing. The directory and file names describe the URL, so a new route normally requires creating a file in the correct location rather than registering a path in a central router configuration.

#1 Best Overall
HP OmniBook 3 17.3 inch Laptop PC, FHD Display, AMD Ryzen 3 30, 8 GB RAM, 512 GB SSD, AMD Radeon 610M Graphics, Windows 11 Home, Mica Silver, 17-dp0199nr
  • FULL HD IPS DISPLAY - Enjoy vibrant, crystal-clear images with 178-degree wide-viewing angles
  • AMD RYZEN 3 30 PROCESSOR - Everyday performance you can count on; Multitask, stream, game casually, and edit photos smoothly with responsive power and vibrant HDR visuals
  • ENJOY UP TO 14 HOURS AND 15 MINUTES OF BATTERY LIFE - HP Fast Charge restores battery from 0 to 50% in approximately 45 minutes
  • AMD RADEON 610M GRAPHICS - Experience smooth entertainment; Built for streaming and multitasking, enjoy realistic visuals and efficient performance for work and play
  • STORAGE AND MEMORY - 512 GB PCIe NVMe M.2 SSD offers fast speed and efficient storage; and 8 GB LPDDR5 RAM memory boosts performance with higher bandwidth

Next.js has two routing systems. The App Router is the current model for new applications and uses the app directory, nested layouts, React Server Components, and newer routing conventions. The Pages Router uses the pages directory and remains supported, especially in existing applications.

How do you create a Next.js project?

Create a starter application with the current project generator:

npx create-next-app@latest routing-demo
cd routing-demo
npm run dev

When the setup wizard asks whether to use the app directory or App Router, accept that option. The wizard’s exact questions and defaults can change between releases, so do not rely on a fixed sequence of prompts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Open http://localhost:3000 in a browser. Port 3000 is the normal development port, but Next.js may choose another port if port 3000 is already occupied.

How does the App Router map files to URLs?

In the App Router, each folder adds a URL segment, and a page.tsx file supplies the UI for the complete route. A folder without a page.tsx file is not automatically a public page.

app/
├── page.tsx
└── about/
    └── page.tsx
// app/page.tsx
export default function HomePage() {
  return <h1>Home</h1>
}

// app/about/page.tsx
export default function AboutPage() {
  return <h1>About</h1>
}
File URL Purpose
app/page.tsx / Home page
app/about/page.tsx /about About page
app/dashboard/settings/page.tsx /dashboard/settings Nested settings page

How do nested routes work?

Nested routes work by nesting folders. Each folder contributes one path segment:

app/
└── dashboard/
    ├── page.tsx
    └── settings/
        └── page.tsx

app/dashboard/page.tsx becomes /dashboard, while app/dashboard/settings/page.tsx becomes /dashboard/settings. This folder-to-segment relationship is the core App Router mental model.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do layouts provide shared UI?

A layout.tsx file wraps its child routes and is intended for persistent UI such as headers, navigation, sidebars, and footers.

app/
├── layout.tsx
├── page.tsx
└── dashboard/
    ├── layout.tsx
    ├── page.tsx
    └── settings/
        └── page.tsx
// app/layout.tsx
import type { ReactNode } from 'react'

export default function RootLayout({
  children,
}: {
  children: ReactNode
}) {
  return (
    <html lang="en">
      <body>
        <header>Site header</header>
        {children}
      </body>
    </html>
  )
}
// app/dashboard/layout.tsx
import type { ReactNode } from 'react'

export default function DashboardLayout({
  children,
}: {
  children: ReactNode
}) {
  return (
    <section>
      <nav>Dashboard navigation</nav>
      <main>{children}</main>
    </section>
  )
}

The root layout wraps every route below app. The dashboard layout wraps both /dashboard and /dashboard/settings. App Router layouts are designed to preserve state and remain interactive across navigation rather than being fully recreated on every route change.

How do you link between Next.js routes?

Use Link from next/link for visible internal navigation:

import Link from 'next/link'

export default function Navigation() {
  return (
    <nav>
      <Link href="/">Home</Link>
      <Link href="/about">About</Link>
      <Link href="/dashboard">Dashboard</Link>
    </nav>
  )
}

Link uses Next.js navigation behavior and can enable client-side navigation and prefetching when appropriate for the route and context. Do not use useRouter() for every link; imperative navigation is better suited to conditional or action-based navigation.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
TechGarden Wired Number Pad, USB Numeric Keypad 19 Key Number Keypad Keyboard for Laptop PC Computer Notebook, Big Print Letters - Black
  • Easy to Use - Our USB wired numpad does not require any driver or battery; easy to install, plug and play, gives you a stable connection.
  • Quiet & Soft Touch - Integrated ergonomic tilt provides comfortable typing, helps reduce the wrist strain. Low noise of the 19-key USB numeric keypad gives you a quiet and soft touch.
  • USB Wired Number Pad - Full-size 19mm keys improve speed and accuracy by making it easier to locate and press the numbers you are looking for. Numeric keypad supports NumLock.
  • Lightweight & Portable - The black numeric keypads are perfect for working on spreadsheet, you can works household, school, business trips, or daily use, very convenient number use.
  • Wide Compatibility - Compatible for Windows 2000, XP, Vista, or Windows 7/8/10, Android operating systems. Works with PC, desktop, notebook and other devices with USB ports.

Use a normal anchor for an external destination:

<a href="https://example.com">External site</a>

For site-wide links, prefer root-relative URLs such as /about. A link written as about is relative and can resolve against the current path in an unexpected way.

How do dynamic routes work in Next.js?

A dynamic route uses square brackets in a folder name. The folder name becomes the parameter name, so [slug] produces params.slug and [id] produces params.id.

app/
└── blog/
    └── [slug]/
        └── page.tsx

This route matches /blog/hello, /blog/next-routing, and /blog/2026-update. The current Next.js 16-style App Router example reads the asynchronous params value like this:

type PageProps = {
  params: Promise<{ slug: string }>
}

export default async function BlogPostPage({ params }: PageProps) {
  const { slug } = await params

  return <h1>Post: {slug}</h1>
}

Recent Next.js versions have changed the exact type and access pattern for params. The example above targets the current asynchronous form; older projects may show params.slug directly. Follow the generated types and version-specific documentation in an existing application rather than copying parameter syntax blindly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Dynamic routes can be rendered at request time or generated ahead of time, depending on the route’s data and configuration. A dynamic segment describes the URL shape; it does not by itself decide when the page’s data is produced.

How do catch-all and optional catch-all routes work?

Catch-all routes capture multiple path segments as an array. An optional catch-all route also matches the base directory path.

Folder Example matches Parameter
[...parts] /docs/getting-started/routing parts: string[]
[[...parts]] /docs and /docs/getting-started An array when segments exist; absent for the base path
app/
└── docs/
    └── [...parts]/
        └── page.tsx
type PageProps = {
  params: Promise<{ parts: string[] }>
}

export default async function DocsPage({ params }: PageProps) {
  const { parts } = await params

  return <p>Path: {parts.join(' / ')}</p>
}

The Pages Router uses the same bracket concepts, including pages/blog/[slug].js, pages/shop/[...slug].js, and pages/shop/[[...slug]].js. The dynamic-routes documentation covers those conventions.

What is the difference between path parameters and search parameters?

A path parameter is part of the URL structure, while a search parameter follows a question mark. In /blog/hello, hello is a dynamic path parameter; in /blog?sort=latest, sort=latest is a search parameter.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For example, /products?category=books&sort=price has the pathname /products and two search parameters: category=books and sort=price.

In an App Router page, read query-string values through the asynchronous searchParams prop:

type PageProps = {
  searchParams: Promise<{
    category?: string
    sort?: string
  }>
}

export default async function ProductsPage({ searchParams }: PageProps) {
  const query = await searchParams

  return (
    <p>
      Category: {query.category ?? 'all'}
      <br />
      Sort: {query.sort ?? 'relevance'}
    </p>
  )
}

Use useSearchParams() when a Client Component needs to read the query string in the browser. A client component using that hook must begin with 'use client'. Do not confuse useSearchParams() with a dynamic segment such as [slug].

Rank #3
Foldable Silicone Keyboard, USB Wired Rollup Keyboard for Desktop, Laptop
  • Multiple function: Flexible, Soft, Foldable, Roll-up, Silent, Waterproof, Dustproof, Lightweight, Portable and easy to store. Multiple function make it an extraordinary computer keyboard!
  • Soft silicone material: Made of high intensity and high elasticity silicone gel, non-toxic and odorless. Flexible material allow you to roll up freely for storage, very handy and convenient to take along with your notebook, laptop and mac.
  • Waterproof and dustproof: No additional keyboard cover skin required, food crumbs or dust can be easily cleaned thoroughly. Clean the silicone keyboard with water, alcohol, or alcohol based disinfectant.
  • Full-size Standard Keyboard: 17.5'' length 5.5'' width, the size is the same as normal qwerty keyboards, but more convenient and portable than them. Keys are sensitive and not cramped, avoid many typing errors.
  • Simple Wired USB connection , support main USB port, Plug and Use. Application: Laptop, Notebook, Computer.

How do you navigate programmatically?

Use useRouter from next/navigation when code needs to navigate after an action, such as completing a form submission.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
'use client'

import { useRouter } from 'next/navigation'

export default function ContinueButton() {
  const router = useRouter()

  return (
    <button onClick={() => router.push('/dashboard')}>
      Continue
    </button>
  )
}
Method Effect Typical use
router.push(path) Adds a browser history entry Move to a new page after an action
router.replace(path) Navigates without adding a history entry Replace a temporary or transitional URL
router.back() Moves backward in browser history Back buttons
router.forward() Moves forward in browser history Forward controls
router.refresh() Requests updated server-rendered data while preserving the client-side route context Refresh data after a mutation

useRouter, usePathname, and useSearchParams are client-side APIs, so their component must use 'use client'. Keep pages as Server Components by default, and add the directive only when the component needs browser APIs, state, event handlers, or client navigation hooks.

How do redirects work in the App Router?

Use redirect() when server-rendered code determines that the current request should go somewhere else:

import { redirect } from 'next/navigation'

export default async function AccountPage() {
  const user = null

  if (!user) {
    redirect('/login')
  }

  return <h1>Account</h1>
}

Use permanentRedirect() when the destination is permanently changing:

import { permanentRedirect } from 'next/navigation'

export default function OldPage() {
  permanentRedirect('/new-page')
}

The framework distinguishes temporary redirects from permanent redirects. Choose the permanent helper only when clients and search engines should treat the old location as permanently replaced. The App Router documentation describes both helpers.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

When should redirects go in next.config.ts?

Use next.config.ts for straightforward, stable path mappings that do not depend on request-specific data:

import type { NextConfig } from 'next'

const nextConfig: NextConfig = {
  async redirects() {
    return [
      {
        source: '/old-blog/:slug',
        destination: '/blog/:slug',
        permanent: true,
      },
    ]
  },
}

export default nextConfig

Use Proxy only when behavior depends on incoming request information or needs more complex request handling. In current Next.js 16 documentation, request interception is called Proxy, and new examples use proxy.ts and export proxy. Older projects and articles may still use middleware.ts and middleware.

Proxy is not a complete session-management or authorization system. Use Proxy for lightweight request-time checks, rewrites, redirects, or header changes, and perform real authorization in appropriate server-side code.

How do route groups organize an application?

Parentheses create route groups that organize files without adding a URL segment. Route groups are useful for separate layouts and large application sections.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
app/
├── (marketing)/
│   ├── layout.tsx
│   └── about/
│       └── page.tsx
└── (shop)/
    ├── layout.tsx
    └── products/
        └── page.tsx

app/(marketing)/about/page.tsx still resolves to /about, and app/(shop)/products/page.tsx resolves to /products. The group names are organizational only.

Two route groups must not create the same final URL. For example, app/(marketing)/about/page.tsx and app/(company)/about/page.tsx both resolve to /about and create a conflict.

Rank #4
Super Mini Wired Keyboard, MCSaite Full Size 78 Keys Keypad Small Portable Fit with Professional or Industrial Use for Computer Laptop Mac Notebook
  • Super Mini Full Size USB Wired Keyboard Portable computer cable 78 - key keyboard, 1.5 meters long, and size 8.66*4.64*0.75 inches/ 220 x118x19. 2 mm
  • Wired USB Connection, convenient and easy to use, support plug and play, and is applicable to any desktop and laptop computers.
  • Small stature high grade PVC material, durable and comfortable with laser engraving keypad.
  • Comfortable buttons perfect coordination with the computer, give you a comfortable office life.
  • Mat to ensure that it is unlikely to slide the keyboard, stable operation, after the 1 million test, stable performance and perfect operation.

What are the App Router’s special route files?

Special files add behavior to a route segment without turning every file into a public page:

File Role
layout.tsx Shared UI around child routes
page.tsx Publicly accessible page UI
loading.tsx Loading UI while a route segment is being rendered
error.tsx Error boundary UI for a route segment
not-found.tsx Not-found UI
global-error.tsx Root-level error UI
route.ts HTTP request handler

Advanced App Router features also include parallel routes for rendering multiple route slots in one layout and intercepting routes for experiences such as modal views that preserve the underlying page. These features are useful to know about but are not prerequisites for a first multi-page application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What is the difference between a page and a route handler?

A page.tsx renders UI, while a route.ts handles HTTP requests. A route handler can create an API endpoint without rendering a React page.

app/
└── api/
    └── hello/
        └── route.ts
import { NextResponse } from 'next/server'

export function GET() {
  return NextResponse.json({ message: 'Hello' })
}

The handler above responds at /api/hello. A route segment generally cannot contain both a page.tsx and a route.ts serving the same URL path, because those files represent different responses for the same segment.

The Pages Router equivalent is an API route such as pages/api/hello.ts. The Pages Router documentation describes those API Routes separately from page routes.

What does a small App Router blog look like?

The following structure combines static pages, a nested dashboard, a shared layout, and a dynamic blog post:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
app/
├── layout.tsx
├── page.tsx
├── about/
│   └── page.tsx
├── blog/
│   ├── page.tsx
│   └── [slug]/
│       └── page.tsx
└── dashboard/
    ├── layout.tsx
    ├── page.tsx
    └── settings/
        └── page.tsx

The home page can link to the main sections:

import Link from 'next/link'

export default function HomePage() {
  return (
    <main>
      <h1>Routing Demo</h1>
      <ul>
        <li><Link href="/about">About</Link></li>
        <li><Link href="/blog">Blog</Link></li>
        <li><Link href="/dashboard">Dashboard</Link></li>
      </ul>
    </main>
  )
}

The blog index can generate links from post data:

import Link from 'next/link'

const posts = [
  { slug: 'hello-next', title: 'Hello Next.js' },
  { slug: 'routing-basics', title: 'Routing Basics' },
]

export default function BlogIndexPage() {
  return (
    <main>
      <h1>Blog</h1>
      <ul>
        {posts.map((post) => (
          <li key={post.slug}>
            <Link href={`/blog/${post.slug}`}>{post.title}</Link>
          </li>
        ))}
      </ul>
    </main>
  )
}

With the dynamic page from the earlier example, the expected results are:

URL Rendered result
/ Routing Demo
/about About page
/blog List of posts
/blog/hello-next Dynamic post page with slug hello-next
/blog/routing-basics Dynamic post page with slug routing-basics

How does the Pages Router differ from the App Router?

The Pages Router maps files in pages to routes, but its layouts, parameter access, and client router imports differ from the App Router.

pages/
├── index.tsx
├── about.tsx
└── blog/
    └── [slug].tsx
Decision App Router Pages Router
Best fit New applications and current Next.js features Existing applications and legacy code
Main directory app pages
Page file page.tsx Any page component file
Shared layouts Nested layout.tsx conventions Custom patterns, often involving _app.tsx
Dynamic parameters Passed through App Router page props Commonly read through useRouter or data-fetching methods
API mechanism route.ts pages/api
Client router import next/navigation next/router

For example, pages/index.tsx maps to /, pages/about.tsx maps to /about, and pages/blog/[slug].tsx maps to a dynamic blog path. The Pages and Layouts documentation covers these conventions.

Do not mix the APIs in one example: app/ uses useRouter from next/navigation, while pages/ uses useRouter from next/router. The Pages Router is not removed, but a new project should generally start with the App Router unless a project requirement says otherwise.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What routing mistakes should beginners check first?

  1. Wrong router import: Check the directory first. Use App Router APIs for app/ and Pages Router APIs for pages/.
  2. Missing 'use client': Add it when a component uses client hooks, browser APIs, state, or event handlers. Do not add it to every component by default.
  3. Missing page.tsx: A component such as app/blog/components/PostCard.tsx is not a public route by itself.
  4. Confusing parameters: /blog/hello contains a path parameter, while /blog?sort=latest contains a search parameter.
  5. Unexpected relative links: Prefer <Link href="/about"> over a relative about URL for site-wide navigation.
  6. Duplicate route groups: Two parenthesized groups can still resolve to the same public URL.
  7. Dynamic collisions: Avoid overlapping static and dynamic folders that make the same URL ambiguous.
  8. Deep-link failures: Test a route by clicking to it and by pasting its URL into a new browser tab or refreshing it directly.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

How should you test a Next.js route after deployment?

Test every important route in two ways: navigate to it from another page, then open the route’s full URL directly or refresh the browser. A route can work during client-side navigation but fail on a hard refresh if the hosting platform does not forward deep-link requests to the Next.js server or correctly serve the generated static file.

Best Value
Sale
Foloda Wireless Number Pads, Numeric Keypad Numpad 22 Keys Portable 2.4 GHz Financial Accounting Number Keyboard Extensions 10 Key for Laptop, PC, Desktop, Surface Pro, Notebook
  • 1.Number Pad for Laptop: Foloda number pad supports NumLock, ESC, Tab, Delete etc. With shortcut key which can open the computer calculator directly. The Multi - Function 10 keys USB keypad is a must - have laptop accessories. It's more unique than most keyboards, perfectly catering to the needs of laptop users who require efficient numeric input during work, study or financial accounting tasks.
  • 2.10 Key USB Keypad: Number Keypad is a great addition to your laptop accessories collection, is only 87g. As a key laptop accessory, Foloda numpad works by 2.4GHz wireless technology, with Plug and Play functionality. You can just plug the receiver into a USB port of your laptop. No device drivers needed, no delays and dropouts, ensuring fast data transmission. The maximum working range up to 32.8 ft. The Receiver is inserted in the battery compartment of the numeric keypad, making it convenient to carry around with your laptop.
  • 3.Wireless Number Pad: Number Pad is made of high quality ABS Material which offer great comfortable touch and precise control, good resilience fast response and reduce the press sound. It also has auto sleep function, lower power consumption, reflecting energy saving. Press any key to awake up the keypad. Power Supply by 2 x AAA Battery ( not included ). This makes it an excellent laptop accessories for use in quiet environments like libraries or offices, where noise - free operation is crucial.
  • 4.10 Key for Laptop: wireless usb number pad, an essential laptop accessory, works with PC, laptop and desktop computers that have Windows 2000 / XP / Vista / 7 / 8 / 10 systems. Whether you're using a Windows laptop for work or entertainment, Foloda usb numeric keypad is a reliable and compatible accessory.
  • 5.USB Number Pad for Laptop: Specialized in Home and try our best to offer the better product and customer service. If you have any question, feel free to contact with us. We are committed to ensuring that your experience with our laptop accessory - the wireless number pad - is nothing short of excellent.

Deployment choice affects routing features. The official deployment guide identifies Node.js server deployment, Docker, static export, and platform integrations as available approaches. A Node.js deployment supports all Next.js features, while static export is limited.

Deployment approach Routing fit Main trade-off
Node.js server Supports all Next.js features Requires server operations
Docker Full deployment option with control over the runtime Requires container and infrastructure management
Static export Suitable for sites whose required features work at build time Server-dependent features and request-time Proxy behavior are unavailable
Managed platform or adapter Can simplify deployment and previews Feature support and runtime behavior vary by provider

Static export does not mean that every dynamic-looking route is impossible. Route behavior depends on the route and build configuration, but server redirects, request-time Proxy behavior, and other server-dependent features cannot be assumed to work on a static-only host. A static host must also serve deep links such as /blog/example correctly.

Where should you deploy a beginner Next.js application?

Choose a deployment platform based on the routing features and operational control you need, not because Next.js requires one particular host.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Vercel: A practical first choice when you want the shortest path from a Git repository to a managed Next.js deployment, framework integrations, and preview deployments. Vercel describes standard Next.js deployment as zero-configuration in its Next.js documentation, but Vercel is not required; Next.js also supports Node.js, Docker, static hosting in limited cases, and other integrations.
  • Cloudflare Workers: Worth considering for a globally distributed Workers-oriented architecture. Cloudflare documents App Router, Pages Router, route handlers, SSR, SSG, ISR, Server Actions, and streaming through its adapter, while also documenting runtime-specific limitations such as Node.js middleware support. Check compatibility before choosing it for a Node-dependent application.
  • Netlify: A managed option whose OpenNext-based integration supports the App Router and major Next.js features. Verify that the adapter supports the exact features your application uses.
  • Node.js or Docker self-hosting: Best when runtime control, region, networking, data locality, or infrastructure cost matters more than managed convenience. The self-hosting guidance recommends placing a reverse proxy such as nginx in front of the Next.js server for request validation, rate limiting, payload controls, and related protections.

Do not buy a separate routing library for these requirements. Next.js already provides file-system routes, layouts, links, dynamic segments, redirects, route handlers, and request interception mechanisms.

What is the simplest Next.js routing mental model?

Think of an App Router project as a mapping from file-system conventions to URL behavior: folders form the path, page.tsx renders a public page, layout.tsx wraps related pages, square brackets capture URL data, and special files add loading, error, not-found, or HTTP behavior.

Start with Link for normal navigation. Add a dynamic segment when the URL identifies a resource, use searchParams for optional filtering and sorting, use imperative navigation only after an action or conditional check, and select server deployment when the application needs request-time features.

Frequently Asked Questions

Should a new Next.js project use the App Router or Pages Router?

A new Next.js project should generally use the App Router because it is the current routing model and supports current Next.js features. The Pages Router remains supported and is often the right choice when extending an existing Pages Router application.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Why does useRouter fail in an App Router component?

In an App Router component, import useRouter from next/navigation, not next/router, and mark the component with 'use client'. The next/router import belongs to the Pages Router.

What is the difference between [slug] and searchParams in Next.js?

A folder named [slug] captures a path segment such as /blog/hello as params.slug. A query string such as /blog?sort=latest is read through searchParams in a page or useSearchParams() in a Client Component.

Why does a Next.js route work after clicking a link but return 404 after refresh?

A route that works after clicking a link but returns 404 on refresh usually indicates a deployment or deep-link configuration problem. Test the full URL directly and configure the host to forward nested requests to the Next.js server or serve the generated static file correctly.

The Bottom Line

Bottom line: For new applications, learn the App Router as a file-system-to-URL system: folders create segments, page.tsx creates pages, layouts provide shared UI, square brackets capture dynamic data, and Link handles normal navigation. Keep Pages Router code and imports separate, test direct URL loads after deployment, and choose a server-capable deployment when your routing depends on request-time behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.