<page-route>

The <page-route> component is the main route container. It mounts slotted content, a lazy src file, or a JavaScript-provided component only when the current pathname matches its route pattern.

html
1<page-route path="/dashboard">2    <h2>Dashboard View</h2>3</page-route>

Attributes

AttributeTypeDefaultDescription
pathstring"/"The pathname pattern to match (supports parameters like /:id).
exactbooleantrueWhen true, matches the path strictly. When false, matches paths starting with the pattern.
srcstringundefinedRelative path to an HTML, text, or JavaScript module file to lazy load.
titlestringundefinedUpdates the document title when this route becomes active.
namestringundefinedMutually exclusive route group identifier (similar to a Switch statement).

Dynamic Parameters

Use a colon : to define path parameters. You can retrieve these values in nested HTML via <page-data> or in JavaScript:

html
1<page-route path="/users/:userId">2    <h2>User ID: <page-data param="userId"></page-data></h2>3</page-route>

Nested Layouts

Set exact="false" on a parent route that should stay active while child routes match. Child path values are appended to the closest parent route path.

html
1<page-route path="/teams/:teamId" exact="false">2    <h1>Team <page-data param="teamId">unknown</page-data></h1>3 4    <nav>5        <page-link path="$/members">Members</page-link>6        <page-link path="$/settings">Settings</page-link>7    </nav>8 9    <page-route path="/members" src="./teams/members.html"></page-route>10    <page-route path="/settings" src="./teams/settings.js"></page-route>11</page-route>

Switch-Like Grouping (name)

To ensure only one route in a group renders at a time (preventing overlapping matches), assign them the same name attribute. The router will evaluate them in order and mount only the first match:

html
1<!-- Mutually exclusive routing -->2<page-route name="view-group" path="/users/new">3    <h2>Create New User</h2>4</page-route>5 6<page-route name="view-group" path="/users/:userId">7    <h2>User Profile</h2>8</page-route>

Lazy Loading (src)

Instead of embedding all views in the main document, load them on-demand by specifying a file in the src attribute.

You can define a loading state and a fallback UI (shown if the request fails) using the loading and fallback slots:

html
1<page-route path="/about" src="./pages/about-page.html">2    <div slot="loading">Loading page template...</div>3    <div slot="fallback">Oops! Failed to load page.</div>4</page-route>

Supported Lazy-Loaded Formats

When loading a JavaScript file, the module must default-export one of the following:

javascript
1// ./pages/user-details.js2const { html } = BFS.MARKUP3 4export default (data, params, query) => html`5    <h2>User Profile: ${params.userId}</h2>6    <p>Role: ${data.role}</p>7    <p>Tab: ${query.tab || 'overview'}</p>8`

Caching and Lifecycle

To prevent memory leaks and optimize performance:

edit this doc