liveBook · Manning

Chapter 10: Navigation

What you will learn in chapter 10 of Vanilla Web

Introduces navigation as movement between views and routing as matching a URL to content, while explaining why SPA routing still depends on the browser and server.

After this chapter you will be able to

What it builds on

Section by section

Introduction

Introduces navigation as movement between views and routing as matching a URL to content, while explaining why SPA routing still depends on the browser and server.

Key terms: navigation, router, route, URL, view, client-side router, browser’s native history, deep links, accessible and crawlable links, page component

10.1 Navigation and routing on the Web

Defines routing, compares where navigation decisions happen, and explains why view changes must work with browser URLs and history.

Key terms: routing, multi-page application (MPA), single-page application (SPA), hybrid architecture, HTML shell, router, address bar, back and forward buttons, bookmarks, history traversal

10.1.1 Discoverability, accessibility, and graceful degradation

The section explains how routing choices affect discoverability and accessibility, and why navigation should keep working when client-side enhancements are unavailable.

Key terms: readable paths, fragment-based routing, <a href> links, canonical URLs, HTTP status codes, SPA-only rendering, server-rendered, statically rendered, prerendered HTML, graceful degradation

10.1.2 Native navigation

This section explains what triggers browser navigation by default and what a native navigation replaces.

Key terms: native navigation, client-side router, JavaScript intercepts, JavaScript context, application state, focus, scroll position

10.1.3 Client-side router

The section frames SPA routing as selective interception of native navigation and outlines the responsibilities of a client-side router.

Key terms: SPA routing, same-origin navigations, same-document updates, native navigation, external links, internal links, real links, deep links, client-side router, route data

10.1.4 Navigation and routing definitions

The section frames navigation and routing as using URLs to show content for a particular route.

Key terms: navigation, routing, URLs, route, views

10.1.5 Friendly URLs

This section explains how descriptive URLs communicate a resource’s meaning and why they are preferable to opaque URLs.

Key terms: friendly URL, clean URL, human-readable URL, descriptive path, query parameters

10.1.6 Real URLs

This section defines a real URL by whether it reaches the correct content directly and explains how SPAs and MPAs support that behavior.

Key terms: real URL, native navigation, temporary client-side state, SPA, MPA, application shell, client-side router

10.1.7 Real links

This section explains why navigation should start with real HTML links and how a client-side router can enhance them without losing native behavior.

Key terms: real link, <a>, href, progressively enhance, client-side router, normal clicks, browser history, card link, ::before, aria-labelledby

10.1.8 URL parts

Distinguishes the path, query string, and hash in a URL and explains why hash routing is generally discouraged as a primary strategy.

Key terms: path, query string, hash, fragment, hash routing, native URL model, server integration, discoverability

10.1.9 Route

This section defines a route, illustrates a named path parameter, and explains where routes are resolved and what makes their URLs useful.

Key terms: URL, route, URL pattern, route pattern, named path parameter, slug, MPA, SPA, hybrid app, server

10.1.10 Canonical route shapes

Explains how to choose consistent route URLs and identify preferred public URLs without creating duplicate variants.

Key terms: canonical shape, normalize, trailing slashes, query parameters, canonical URL, public content, discoverability, hreflang, multilingual public content, initial HTML response

10.1.11 Route state

Explains how to represent shareable route state in query strings and decide whether changes should create browser history entries.

Key terms: route state, query string, defaults, url.searchParams.sort(), canonicalizing query strings, history, Back, normalizing state

10.2 The server

This section explains why the server must handle direct URL requests correctly before a client-side router can render a view.

Key terms: server, client-side router, shell document, SPA entry document, rewrite rule, API route, 404 Not Found, soft 404, subpath, base path

10.3 Navigation interception

This section contrasts full-page navigation with client-side interception and introduces the two browser APIs used to manage navigation.

Key terms: multi-page application, client-side routed application, intercept, Navigation API, History API, history.pushState(), popstate

10.3.1 Navigation entry list

This section explains what the Navigation API’s entry list represents, how Back and Forward traverse its entries, and how its visibility differs from the History API.

Key terms: session history, navigation entry list, browsing context, same-origin entries, multi-page application, client-side routed application, same document, traversal, URL, index

10.3.2 The Navigation API

Introduces the Navigation API as a central way to intercept navigations for same-document routing and explains the router’s resulting rendering, focus, and scroll responsibilities.

Key terms: Navigation API, navigation, navigate, event.intercept(), same-document navigation, Baseline 2026, focusReset: "manual", scroll: "manual", event.scroll()

10.3.3 Cancellation with event.signal

This section explains how the Navigation API cancels work from a superseded navigation and how to treat the resulting abort without showing an error.

Key terms: Navigation API, event.signal, AbortSignal, AbortError, navigateerror

10.3.4 Form submissions

Explains how the Navigation API exposes GET and POST form submissions to a router, and why a History API fallback needs separate form handling.

Key terms: Navigation API, navigate, event.destination.url, event.formData, History API fallback, native browser navigation, submit event

10.3.5 Observing completion

Explains how to observe intercepted navigation outcomes, why Navigation API events simplify interception, and why production routers still need a fallback.

Key terms: event.intercept(), navigatesuccess, navigateerror, navigation.transition, finished, Navigation API, navigation event, manual click interception, feature detection, History API

10.3.6 History API fallback

This section explains what a History API navigation fallback can do, what it must handle itself, and why it cannot fully replace the Navigation API.

Key terms: History API, history.pushState(), history.replaceState(), popstate, real links, same-document application navigations, modifier keys, hash jumps, idempotent GET forms, polyfill

10.4 Route matching

Introduces how a client-side router selects a route from the current path, including static and parameterized patterns and the browser APIs available for matching them.

Key terms: route matching, route patterns, current URL path, named path parameter, dynamic, route pattern, URLPattern, Baseline 2025, regular expression fallback

10.4.1 Simple matching

This subsection presents hardcoded route matching as a learning-friendly option for very small apps and explains why it does not scale well.

Key terms: hardcoded switch statement, static paths, dynamic product path, segment boundaries, URL parameters

10.4.2 Matching routes with URLPattern

This section explains how to match URL paths to routes with URLPattern or a limited regex fallback, then choose a route in a safe order.

Key terms: URLPattern, pathname, exec(), named groups, matcher function, regex fallback, literal segments, :name parameters, route order, first route

10.4.3 Testing the matcher

The section explains why a small Vanilla route matcher is easy to test in isolation and how testing changes for browser-dependent routing behavior.

Key terms: matcher, test in isolation, unit-tested, View Transitions, browser navigation event

10.5 Summary

Where this is used later

Concepts explained in this chapter

← Chapter 9: Advanced web components Chapter 11: Building a router →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.