Static
Private
loaderPrivate static ReplaySubject used as the Router loader.
This loader emits every time Routes are added, whilst
the size being 0
, so either for the first time after construction
or after the Router was cleared.
Readonly
[iterator]declare
d well-known Symbol.iterator
property. This declaration enforces
correct typing when retrieving the Subscribable from the well-known
Symbol.observable
method by voiding the inherited Symbol.iterator
.
Readonly
baseAn absolute baseHref for navigation.
'/'
Readonly
hashWhether to employ hashBased routing.
false
Readonly
outletdocument.body
Private
Readonly
changesInternally used BehaviorSubject containing and emitting every navigated State.
Static
[observable]Static Symbol.observable
method returning a Subscribable. The
returned Subscribable mirrors the private loader and is
used for initializations after a new global Route tree was
added to the Router.
A Subscribable emitting this Router.
Subscribe to the Router:
import { Router } from '@sgrud/shell';
import { from } from 'rxjs';
from(Router).subscribe(console.log);
Well-known Symbol.observable
method returning a Subscribable. The
returned Subscribable emits the current State and every
time this changes.
A Subscribable emitting States.
Subscribe to upcoming States:
import { Router } from '@sgrud/shell';
import { from } from 'rxjs';
from(new Router()).subscribe(console.log);
connecting helper method. Calling this method will connect a
handler to the global onpopstate
event, invoking navigate with
the appropriate arguments. This method furthermore allows the properties
Router.baseHref, Router.hashBased and Router.outlet
to be overridden. Invoking the connect method throws an error if called
more than once, without invoking the disconnect method in between
invocations.
A ReferenceError if already connected.
disconnecting helper method. Calling this method (after calling
connect) will disconnect the previously connected
handler from the global onpopstate
event. Further, the arguments passed
to connect are revoked, meaning the default values of the
properties baseHref, hashBased and outlet are
restored. Calling this method without previously connecting the
Router throws an error.
A ReferenceError if already disconnected.
Implementation of the handle method as required by the Queue
interface contract. It is called internally by the navigate method
after all Queues have been invoked. It is therefore considered the
default or fallback Queue and handles the rendering of the supplied
state
.
An Observable of the handled State.
Segment joining helper. The supplied segment
is converted to
a string by spooling to its top-most parent and iterating through
all children while concatenating every encountered path. If said path is an
(optional) parameter, this portion of the returned string is replaced by
the respective Params value.
The joined Segment in string form.
Lookup helper method. Calling this method while supplying a selector
and optionally an array of routes
to iterate will return the lookuped
Route path for the supplied selector
or undefined
, if it does
not occur within at least one route. When multiple occurrences of the same
selector
exist, the Route path to its first occurrence is
returned.
The lookuped Route path or undefined
.
Main Router matching method. Calling this method while
supplying a path
and optionally an array of routes
will return the
first matching Segment or undefined
, if nothing matches.
If no routes
are supplied, routes previously added to the Router
will be used. The match method represents the backbone of this
Router class, as it, given a list of routes
and a path
, will
determine whether this path represents a match within the list of
routes
, thereby effectively determining navigational integrity.
The path
to match routes
against.
An array of routes
to use for matching.
The first matching Segment or undefined
.
Test if path 'example/route'
matches child
or route
:
import { Router } from '@sgrud/shell';
const path = 'example/route';
const router = new Router();
const child = {
path: 'route'
};
const route = {
path: 'example',
children: [child]
};
router.match(path, [child]); // false
router.match(path, [route]); // true
Main navigate method. Calling this method while supplying either a path
or Segment as navigation target
and optional search
parameters
will normalize the supplied path by trying to match a respective
Segment or directly use the supplied Segment for the next
State. This upcoming State is looped through all linked
Queues and finally handled by the Router itself to
render the resulting, possibly intercepted and mutated State.
An Observable of the navigated State.
An Observable URIError, if nothing matches.
Generated using TypeDoc
Targeted Singleton Router class extending the built-in Set. This Singleton class provides routing and rendering capabilities. Routing is primarily realized by maintaining the inherited Set of Routes and (recursively) matching paths against those Routes, when instructed so by the navigate method. When a matching Segment is found, the corresponding Components are rendered by the handle method (which is part of the implemented Queue contract).
Decorator
Target
Decorator
Singleton