Skip to content

RoutingState class

Attributes: [DataContract] [DebuggerDisplay("NavigationStack Count = {NavigationStack.Count}")]

Defined in

Namespace: ReactiveUI.Reactive Assembly: ReactiveUI.Reactive.dll Full name: ReactiveUI.Reactive.RoutingState Modifiers: public

Summary

View source

RoutingState manages the ViewModel Stack and allows ViewModels to navigate to other ViewModels.

Applies to

net10.0, net10.0-maccatalyst26.0, net10.0-desktop1.0, net10.0-browserwasm1.0, net10.0-tvos26.0, net10.0-windows10.0.19041, net10.0-macos26.0, net10.0-ios26.0, net10.0-android36.0, net9.0, net9.0-tvos18.0, net9.0-macos15.0, net9.0-maccatalyst18.0, net9.0-windows10.0.19041, net9.0-ios18.0, net9.0-desktop1.0, net8.0, net8.0-windows10.0.19041, net8.0-ios18.0, net8.0-maccatalyst18.0, net8.0-macos15.0, net8.0-tvos18.0, net8.0-ios17.5, net8.0-maccatalyst17.5, net8.0-macos14.5, netstandard2.1, net481, net462, net471

Class hierarchy
classDiagram
class RoutingState
class ReactiveObject
ReactiveObject <|-- RoutingState

Inherits from: ReactiveObject

Remarks

Use RoutingState from an IScreen implementation to coordinate navigation in multi-page applications. The stack works in a last-in-first-out fashion, enabling forward navigation via Navigate and back navigation via NavigateBack. Consumers can observe CurrentViewModel or NavigationChanges to drive view presentation.

Examples

<![CDATA[
 public class ShellViewModel : ReactiveObject, IScreen
 {
 public RoutingState Router { get; } = new();
 
 public ShellViewModel()
 {
 Router.Navigate.Execute(new HomeViewModel(this)).Subscribe();
 }
 
 public void ShowDetails() =>
 Router.Navigate.Execute(new DetailsViewModel(this)).Subscribe();
 
 public void GoBack() =>
 Router.NavigateBack.Execute(Unit.Default).Subscribe();
 }
 
 public partial class ShellView : ReactiveUserControl<ShellViewModel>
 {
 public ShellView()
 {
 this.WhenActivated(disposables =>
 ViewModel!.Router.CurrentViewModel
 .Subscribe(viewModel => contentHost.NavigateTo(viewModel))
 .DisposeWith(disposables));
 }
 }
 ]]>

Constructors

NameSummary
.ctorInitializes a new instance of the [RoutingState](# class using the default main thread scheduler.

Properties

NameSummary
NavigationStackGets or sets the current navigation stack, with the last element representing the active view model.
NavigateBackGets a command which will navigate back to the previous element in the stack and emits the new current view model. The command can only execute when at least two view models exist in the...
NavigateGets a command that adds a new element to the navigation stack. The command argument must implement [IRoutableViewModel](# and the command emits the same...
NavigateAndResetGets a command that replaces the entire navigation stack with the supplied view model, effectively resetting navigation history.
CurrentViewModelGets the observable that yields the currently active view model whenever the navigation stack changes.
NavigationChangesGets an observable that signals detailed change sets for the navigation stack, enabling reactive views to animate push/pop operations.
Inherited members

Extension members