liveBook · Manning

Routing

As explained in Build a Frontend Web Framework (From Scratch)

A client-side application component that maps URLs to views or components and manages navigation without a full page reload.

Routing answers a practical question: when the URL changes, which view or components should appear? In a single-page application, the router updates the view and address bar without reloading the entire application. section 1.3.2

Break routing into these responsibilities:

  • Load the initial HTML, JavaScript, and CSS bundles before the application mounts. section 1.3.2
  • Choose the components associated with the current route and create the application view through the Document API. section 1.3.2
  • Handle navigation by replacing the displayed content instead of requesting a complete page from the server. section 1.3.2
  • Distinguish SPA routing from server-side rendering: an SSR router selects components on the server for the requested route, which becomes HTML before hydration. section 1.3.3

One navigation flow

A browser first requests a mostly empty HTML page. JavaScript mounts the application and creates its initial view. When the user navigates to another route, the router selects the new content, updates the view, and changes the address bar without reloading the whole application. In an SSR application, that route instead causes the browser to request a newly rendered HTML page, which is later hydrated to become interactive. section 1.3.2 section 1.3.3

Figure 1.9 SPA navigation among routes
figure

Follow the route-to-route navigation flow in an SPA. section 1.3.2

How Build a Frontend Web Framework (From Scratch) covers it

How deep it goes
Traces SPA loading, mounting, navigation, and SSR route rendering, but stops short of implementing a complete router.
Examples
Uses SPA route navigation, dynamic mounting, SSR-rendered pages, and hydration as concrete examples.
What it assumes
Assumes familiarity with browsers, HTML, JavaScript, CSS, and application components.
What you can do after
Evaluate how SPA and SSR applications respond when users navigate between routes.
How it connects
Connects routing with single-page applications, server-side rendering, components, the Document API, and hydration.

Also explained in

Compare how 22 books explain routing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Frontend Web Framework (From Scratch). The section links point to the parts of the book it draws on.