nav-router
Contents
The router is a component for handling routing inside vanilla and Rindo JavaScript projects.
note
Note: this component should only be used with vanilla and Rindo JavaScript projects.router.
Apps should have a single nav-router component in the codebase.
This component controls all interactions with the browser history and it aggregates updates through an event system.
nav-router is just a URL coordinator for the navigation outlets of navify: nav-nav, nav-tabs, and nav-router-outlet.
That means the nav-router never touches the DOM, it does NOT show the components or emit any kind of lifecycle events, it just tells nav-nav, nav-tabs, and nav-router-outlet what and when to "show" based on the browser's URL.
In order to configure this relationship between components (to load/select) and URLs, nav-router uses a declarative syntax using JSX/HTML to define a tree of routes.
Interfaces
RouterEventDetail
interface RouterEventDetail {
  from: string | null;
  redirectedFrom: string | null;
  to: string;
}
RouterCustomEvent
While not required, this interface can be used in place of the CustomEvent interface for stronger typing with Navify events emitted from this component.
interface RouterCustomEvent extends CustomEvent {
  detail: RouterEventDetail;
  target: HTMLNavRouterElement;
}
Usage
<nav-router>
  <nav-route component="page-tabs">
    <nav-route url="/schedule" component="tab-schedule">
      <nav-route component="page-schedule"></nav-route>
      <nav-route url="/session/:sessionId" component="page-session"></nav-route>
    </nav-route>
    <nav-route url="/speakers" component="tab-speaker">
      <nav-route component="page-speaker-list"></nav-route>
      <nav-route url="/session/:sessionId" component="page-session"></nav-route>
      <nav-route url="/:speakerId" component="page-speaker-detail"></nav-route>
    </nav-route>
    <nav-route url="/map" component="page-map"></nav-route>
    <nav-route url="/about" component="page-about"></nav-route>
  </nav-route>
  <nav-route url="/tutorial" component="page-tutorial"></nav-route>
  <nav-route url="/login" component="page-login"></nav-route>
  <nav-route url="/account" component="page-account"></nav-route>
  <nav-route url="/signup" component="page-signup"></nav-route>
  <nav-route url="/support" component="page-support"></nav-route>
</nav-router>
Properties
root
| Description | The root path to use when matching URLs. By default, this is set to "/", but you can specify an alternate prefix for all URL paths. | 
| Attribute | root | 
| Type | string | 
| Default | '/' | 
useHash
| Description | The router can work in two "modes": - With hash: /index.html#/path/to/page - Without hash: /path/to/pageUsing one or another might depend in the requirements of your app and/or where it's deployed. Usually "hash-less" navigation works better for SEO and it's more user friendly too, but it might requires additional server-side configuration in order to properly work. On the other side hash-navigation is much easier to deploy, it even works over the file protocol. By default, this property is true, change to false to allow hash-less URLs. | 
| Attribute | use-hash | 
| Type | boolean | 
| Default | true | 
Events
| Name | Description | 
|---|---|
navRouteDidChange | Emitted when the route had changed | 
navRouteWillChange | Event emitted when the route is about to change | 
Methods
back
| Description | Go back to previous page in the window.history. | 
| Signature | back() => Promise<void> | 
push
| Description | Navigate to the specified path. | 
| Signature | push(path: string, direction?: RouterDirection, animation?: AnimationBuilder) => Promise<boolean> | 
CSS Shadow Parts
No CSS shadow parts available for this component.
CSS Custom Properties
No CSS custom properties available for this component.
Slots
No slots available for this component.