Table of Contents

Class Router

Namespace
Velvet
Assembly
Velvet.Docs.dll

Navigation controller: consults its blocker, matches paths against a route tree, runs guards and loaders, and maintains a history stack with Back/Forward. V.RouterProvider publishes one to the routing hooks beneath it.

public sealed class Router
Inheritance
object
Router

Constructors

Router(RouteDefinition[], IRouteScopeFactory?)

Builds a router over the given routes.

Properties

CanGoBack

True when the history stack can be moved backward.

CanGoForward

True when the history stack can be moved forward.

Current

The most recently constructed router that has not been disposed. Once that one is disposed, the most recently constructed of the earlier ones still undisposed and still referenced elsewhere; null when there is none. The routing hooks do not read it: they act on the router V.RouterProvider publishes above them.

CurrentActionData

The result of the action the last committed navigation called, keyed by the action's RouteId; empty after any other navigation, and after an action that threw. V.RouterProvider exposes it through ActionData for UseActionData.

CurrentLoaderData

Snapshot of the current loader data, keyed by RouteId. V.RouterProvider exposes this through LoaderData for the UseLoaderData hook.

CurrentLoaderErrors

Snapshot of the current loader errors, keyed by RouteId. V.RouterProvider 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.

Navigation

The navigation in flight, as React Router's router.state.navigation describes it: from the moment its path has matched a route, or matched none, until it commits or gives up, and default — Idle, every other member null — while none is. It describes that attempt and nothing else: an attempt that ends without committing changes nothing CurrentLocation, CurrentLoaderData or CurrentLoaderErrors holds, and reports how it ended through the NavigationResult it returns or the exception it throws. The destination is resolved against the route tree, so it carries the destination's parameters and matches. The form members are null for a submission whose method no form takes or whose body cannot be encoded, as React Router's navigation carries no submission then.

NavigationType

How the committed location was reached, as React Router's historyAction: a step along the history is Pop, as is a router that has committed nothing yet.

RouteBlockerManager

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

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(int, CancellationToken)

Moves delta entries along the history stack, as React Router's navigate(delta) does: negative goes back, positive forward, and a delta past either end lands on the end entry as a memory history's go does. The entry keeps the State and Key it was created with.

NavigateAsync(string, NavigateOptions?, int, CancellationToken)

Navigates as React Router's navigate(to, options) does: options chooses push or replace, the State the new entry carries, and whether a relative path resolves against the route hierarchy or the URL. A fragment in path lands in Hash; a target that is only a fragment keeps the current path and drops its query, as React Router resolves it.

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 Blocker -> Guard -> Loader: the Blocker is asked before the path is matched, and a Guard's redirect is not put to it. A successful Guard redirect records the final target rather than intermediate targets while preserving the originating navigation's history effect. At most four redirects are followed: a fifth is refused and the navigation ends with Error.

SubmitAsync(object?, SubmitOptions?, CancellationToken)

Submits formData as React Router's router.navigate(to, { formMethod, formData }) does; routing.md owns what each method does. A get submission navigates with the form data as its query string. Another form method calls the action of the route the target path matches, reporting Submitting while it runs, and commits its result for UseActionData or its failure as that route's error. A method no form takes commits React Router's 405 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, and when a submission's action returns a result for a route the current location matches. A subscriber that throws out of a loader's 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. A subscriber whose own navigation commits while the router is announcing a location is the last that location reaches: the subscribers after it hear the newer one, which that navigation announces, and not the one it left.

OnNavigationChanged

Raised with the new Navigation whenever it changes. Dispose() clears it without raising this.