Skip to content
FrontDepth, Home

Mini Router

MiddleSenior

Build a client-side router: history, route matching and ranking, links, nested routes, guards and data loaders.

What you will build

You will write a small client-side router in plain JavaScript, in the style of React Router's data routers. It starts with a memory history that has the API of the history package, matches URLs against route patterns and ranks them by specificity, keeps the result in a state you can subscribe to, and turns clicks on ordinary links into navigations.

Then you add nested routes that render into their parent's outlet, guards that cancel or redirect a navigation (back/forward included), and data loaders that run in parallel and are aborted when a newer navigation starts. In the last step a small team directory runs on your router in the preview.

What you will learn

  • How session history works: entries, push and replace, back/forward, and why `pushState` fires no event
  • How a router matches URL patterns and ranks routes by specificity
  • How to intercept link clicks without breaking new tabs, downloads and links to other sites
  • How nested routes become branches of a tree and render through outlets
  • How guards and data loaders fit into one navigation pipeline, and how `AbortController` cancels a stale navigation

Steps

Other hands-on work on the same topics.

Guided tours through the source of real libraries that rely on it.