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¶
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¶
| Name | Summary |
|---|---|
| .ctor | Initializes a new instance of the [RoutingState](# class using the default main thread scheduler. |
Properties¶
| Name | Summary |
|---|---|
| NavigationStack | Gets or sets the current navigation stack, with the last element representing the active view model. |
| NavigateBack | Gets 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... |
| Navigate | Gets a command that adds a new element to the navigation stack. The command argument must implement [IRoutableViewModel](# and the command emits the same... |
| NavigateAndReset | Gets a command that replaces the entire navigation stack with the supplied view model, effectively resetting navigation history. |
| CurrentViewModel | Gets the observable that yields the currently active view model whenever the navigation stack changes. |
| NavigationChanges | Gets an observable that signals detailed change sets for the navigation stack, enabling reactive views to animate push/pop operations. |
Inherited members
ReactiveUI.Reactive.ReactiveObject.SuppressChangeNotificationsReactiveUI.Reactive.ReactiveObject.AreChangeNotificationsEnabledReactiveUI.Reactive.ReactiveObject.DelayChangeNotificationsReactiveUI.Reactive.ReactiveObject.#ctorReactiveUI.Reactive.ReactiveObject.ChangingReactiveUI.Reactive.ReactiveObject.ChangedReactiveUI.Reactive.ReactiveObject.ThrownExceptionsReactiveUI.Reactive.ReactiveObject.PropertyChangingReactiveUI.Reactive.ReactiveObject.PropertyChangedSystem.Object.Equals(System.Object)System.Object.Equals(System.Object,System.Object)System.Object.GetHashCodeSystem.Object.GetTypeSystem.Object.MemberwiseCloneSystem.Object.ReferenceEquals(System.Object,System.Object)System.Object.ToString