· 2 min read
Breadcrumbs, and a nav marker that was never in the HTML
Pages inside a section show where they are: Home / Projects / CV builder, Home / Blog / #css. Section pages (/projects, /about) don't, because the nav already…
What we did
- Pages inside a section show where they are:
Home / Projects / CV builder,Home / Blog / #css. Section pages (/projects,/about) don't, because the nav already says that. Breadcrumbs.sveltesits in the root layout, at the top of<main>. The section comes from the nav's own list, nowsectionsinlinks.ts, shared by both. The page's name comes from its load data: each nested route returnscrumb(a post's title, a tool's name,#tag), typed inApp.PageData.- The nav now marks the section on pages inside it too:
aria-current="true"on Projects while I'm on/projects/cv, with the same marker. Before, no link was marked there. - Fixed an old bug on the way: the nav's
aria-currentand marker were never in the prerendered HTML. They only appeared once the JS ran.
What I learned
- A breadcrumb is a
<nav aria-label="Breadcrumb">with an ordered list. The last item is the current page: text witharia-current="page", not a link to where I already am. content: '/' / ''sets a pseudo-element's alt text. The second string is empty, so a screen reader doesn't read "slash" between the items.- While prerendering,
resolve()gives relative links (./projects,../projects), becausepaths.relativeis on by default. Sopage.url.pathname === resolve(href)never matched in the HTML, only in the browser.page.route.id(/projects/cv,/blog/[slug]) has no base path and is the same on the server and the client, so the nav and the breadcrumbs compare route ids now. - To find it I looked at the build output, not the page:
greponbuild/projects/cv.htmlshowed no breadcrumbs, even though they were on screen. aria-current="true"means "the current item in this set". It's the right value for a section I'm inside but not on.
Links
- WAI-ARIA APG: Breadcrumb pattern
- MDN: aria-current
- MDN: content, alternative text
- SvelteKit: paths.relative
- SvelteKit: page.route
Next
- Phase 9: the
Seocomponent. Breadcrumbs could also go in as structured data (BreadcrumbList) there.