Table of Contents

Class Router

Namespace
Velvet
Assembly
Velvet.Docs.dll

Navigation controller: matches paths against a route tree, runs guards / blockers / loaders, and maintains a history stack with Back/Forward. The active instance is exposed as Current.

public sealed class Router
Inheritance
object
Router

Constructors

Router(RouteDefinition[], IRouteScopeFactory?)

Builds a router over the given routes and sets it as Current.

Properties

CanGoBack

True when the history stack can be moved backward.

CanGoForward

True when the history stack can be moved forward.

Current

The currently active Router instance, or null when none is mounted. Set when a router is constructed and cleared on Dispose().

CurrentLoaderData

Snapshot of the current loader data, keyed by RouteId. The router's root Provider exposes this through LoaderData for the UseLoaderData hook.

CurrentLoaderErrors

Snapshot of the current loader errors, keyed by RouteId. The router's root Provider exposes this through Errors for the UseRouteError hook and for ErrorElement rendering.

CurrentLocation

Location information for the most recently successful navigation. null before the first navigation.

RouteBlockerManager

Blocker manager attached to this router. Referenced from the UseBlocker hook.

Status

Current processing state of the router.

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

GetLoaderData(string)

Returns the loader data corresponding to the given routeId; null when not present.

GoBack(CancellationToken)

Moves one step back on the history stack. Returns Cancelled when CanGoBack is false.

GoForward(CancellationToken)

Moves one step forward on the history stack. Returns Cancelled when CanGoForward is false.

NavigateAsync(string, NavigationMode, int, CancellationToken)

Navigates with relative resolution anchored to a specific matched-route level (baseRouteIndex), so a .. is interpreted relative to the route the caller is rendered in rather than the leaf route. UseNavigate/V.Navigate pass the caller's Outlet depth here so a relative target anchors at the caller's route level; -1 falls back to the leaf route.

NavigateAsync(string, NavigationMode, CancellationToken)

Navigates to the given path. Evaluation order is Guard -> Blocker -> Loader. A successful Guard redirect records the final target rather than intermediate targets while preserving the originating navigation's history effect. A chain of more than five redirects ends the navigation with Error.

Events

OnLocationChanged

Raised after each successful navigation with the new location. Also re-emitted (with a fresh location identity) when a Suspend-mode loader resolves within the current location. A subscriber that throws out of that re-emit is reported to the console and the resolution stands: the loader's round settles and the route keeps what the loader produced. The same holds for the re-emit that follows a loader failing, where what it keeps is that failure.

OnStatusChanged

Raised whenever Status transitions (idle/matching/loading/etc.), letting hooks such as UseNavigation observe an in-flight navigation.