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
-
objectRouter
Remarks
Models the same navigation controller role as React Router for users migrating from React Router.
Constructors
- Router(RouteDefinition[], IRouteScopeFactory?)
Builds a router over the given
routesand 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
UseLoaderDatahook.
- CurrentLoaderErrors
Snapshot of the current loader errors, keyed by RouteId. The router's root Provider exposes this through Errors for the
UseRouteErrorhook and forErrorElementrendering.
- 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.Navigatepass the caller's Outlet depth here so a relative target anchors at the caller's route level;-1falls back to the leaf route.
- NavigateAsync(string, NavigationMode, CancellationToken)
Navigates to the given path. Evaluation order is Guard -> Blocker -> Loader. When a Guard returns a redirect, recursively navigates to the redirect target with NavigationMode.Replace (the original path is not pushed onto the history). Up to 5 redirects.
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.
- OnStatusChanged
Raised whenever Status transitions (idle/matching/loading/etc.), letting hooks such as
UseNavigationobserve an in-flight navigation.