Fullstack CourseLearn by building
Back to week 3

Topic

Link and navigate

Definition

Next.js Link performs client-side navigation to internal routes, while useRouter exposes imperative navigation methods from a Client Component.

In simpler words

Use Link for a normal in-app destination and router methods after a user action decides where to go.

Navigation should preserve the app experience while retaining normal browser behavior for external destinations.

After this you can

  • Choose Link or useRouter
  • Link internally without a full document reload
  • Navigate after a successful user action

Choose declarative or imperative navigation

A link expresses a destination in the UI and remains accessible to keyboard and assistive-technology users. It is the default for navigation menus, breadcrumbs, and item rows.

Imperative navigation belongs in an event handler, for example after a completed create action. Because handlers run in the browser, the component using useRouter needs the use client directive.

Link and router in their roles

import Link from 'next/link';

<Link href="/course/frontend">Frontend path</Link>

'use client';
const router = useRouter();
router.push('/course/frontend/week/1');

The link describes a destination; router.push follows an event-driven decision.

Mistake: using an anchor for an internal route

// Wrong — requests a new document
<a href="/course/frontend">Frontend</a>

// Right — Next manages internal navigation
<Link href="/course/frontend">Frontend</Link>

Use a normal anchor for external URLs, downloads, and intentionally full navigations.

Navigate after state succeeds

Definition

Navigation after a write should follow a confirmed success state, not just a button click.

In simpler words

Do not send a learner to a detail page for a ticket Nest rejected.

Use router.replace when the old history entry should not return users to a completed sign-in or setup step.

Preserve query parameters deliberately when filters or pagination are part of the destination state.

Live playground

Linking and navigating playground

Compare a Link destination with router.push after an event.

Prefetch + client transition for internal routes.

Keep in mind

  • Prefer Link for visible internal destinations.
  • Use useRouter only in a Client Component and usually inside an event handler.
  • Use anchors for external destinations.

Test

Check your understanding

At least 10 questions — mix of concept, syntax, practical, and logic. Score ≥ 80% (enforced by the API) to save progress.

Checking your session…

10 questions · concept 3 · syntax 2 · practical 3 · logic 2

Concept1. Which statement is the most accurate definition of Next navigation?
Syntax2. Which code-level choice is consistent with Next navigation?
Practical3. A reviewer sees this situation. Which decision best applies Next navigation?
Logic4. What reasoning correctly explains why this approach works for Next navigation?
Concept5. Which boundary does the correct use of Next navigation preserve?
Practical6. What is the safest next step when implementing Next navigation?
Syntax7. Which implementation direction matches the rule for Next navigation?
Logic8. Which consequence follows from applying Next navigation correctly?
Concept9. Which claim about Next navigation is true in this monorepo?
Practical10. Which team practice best demonstrates Next navigation?