Command Palette

Search for a command to run...

Hectal
Phase 11: Network and Browser APIs
JavaScript · Exercise 4 of 5 PreviousNext
Intermediate

A hash router for three pages

The page has four sections with data-route values /, /about, /contact and notfound.

Show only the section whose data-route matches the route after # (no hash means /). For an unknown route, show the notfound section.

Give the matching nav link the class active, and update the view whenever the hash changes.

Keep the small click handler at the bottom of the starter: it makes # links work inside Hectal's sandboxed preview.

What Check tests

  1. With no hash, only the Home section is visible
  2. Setting the hash to #/about shows only About
  3. Clicking the Contact link shows only Contact
  4. The Contact link has the class active, the others don't
  5. An unknown route shows the 404 section

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

Runs in your browser. Your code is saved here.

Your page

Press Run to see the page.

Console

Nothing logged yet.