Skip to main content

View

URL-based view container for single-page routing.

Usage

<w-view path="/home">
<h1>Home Page</h1>
<p>Welcome to the home page.</p>
</w-view>

<w-view path="/about">
<h1>About Page</h1>
<p>Learn more about us.</p>
</w-view>

Props

PropTypeDefaultDescription
pathstring""URL path that activates this view
labelstring""Accessible label (adds landmark role)
activebooleanfalseWhether the view is currently visible

Events

EventDetailDescription
view-change{ active, path }Fired when visibility changes

Methods

MethodDescription
navigate()Navigate to this view's path
isActive()Check if currently active
refresh()Force refresh visibility state

Examples

With Navigation

<w-nav label="Navigation">
<w-slot item><w-link href="/home">Home</w-link></w-slot>
<w-slot item><w-link href="/about">About</w-link></w-slot>
<w-slot item><w-link href="/contact">Contact</w-link></w-slot>
</w-nav>

<main>
<w-view path="/home">
<h1>Home</h1>
</w-view>

<w-view path="/about">
<h1>About</h1>
</w-view>

<w-view path="/contact">
<h1>Contact</h1>
</w-view>
</main>

With Accessible Label

When you add a label, the view becomes a landmark region:

<w-view path="/dashboard" label="Dashboard content">
<h1>Dashboard</h1>
</w-view>

This renders with role="region" and aria-label="Dashboard content".

Nested Routes

<w-view path="/settings">
<h1>Settings</h1>

<w-nav label="Settings sections">
<w-slot item><w-link href="/settings/profile">Profile</w-link></w-slot>
<w-slot item><w-link href="/settings/account">Account</w-link></w-slot>
</w-nav>

<w-view path="/settings/profile">
<h2>Profile Settings</h2>
</w-view>

<w-view path="/settings/account">
<h2>Account Settings</h2>
</w-view>
</w-view>

Routing Modes

Views automatically use the routing mode configured in App.start():

Hash Mode

App.start({ hash: true });

URLs: https://example.com/#/about

Pathname Mode

App.start({ hash: false, base: "/app" });

URLs: https://example.com/app/about

Path Matching

  • Paths are matched case-insensitively
  • Leading slashes are normalized (/about matches about)
  • Hyphens are ignored in matching (/about-us matches /aboutus)

Styling

Views are hidden with display: none when inactive:

/* Active view styling */
w-view[active] {
animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
from { opacity: 0; }
to { opacity: 1; }
}

Accessibility

  • Hidden views use hidden attribute (removed from accessibility tree)
  • Optional role="region" when label is provided
  • aria-label for landmark navigation
  • No role by default (just a container)