# RoutingState

Version: 0.5.0
Framework commit: d503df2befa756e681fcdc6250e9552dc7388bea
Canonical URL: /docs/0.5.0/api/ferroui-reactiveui/routing/struct-routingstate/

**struct** · [`ferroui-reactiveui`](/docs/0.5.0/api/ferroui-reactiveui/) · v0.5.0

```rust
struct RoutingState
```

The stack of view models of a screen, and the commands that navigate it (`RoutingState`).

An `IScreen` holds one to coordinate the navigation of an application of
several pages. The stack is last in, first out: `navigate` pushes a view
model, `navigate_back` pops one, and
`navigate_and_reset` replaces the whole stack.

Every notification of the navigation is an observable of values:
`current_view_model` gives the view model on top of the stack,
`navigation_stack_changed` gives the whole stack after each
change, and `can_navigate_back` whether there is a view model to go
back to.

The router is shared (`Rc<RoutingState>`); its observables and commands refer to it weakly, so
that they do not keep it alive.

[View source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L50)

## Members

- [`new`](#function-new)
- [`with_scheduler`](#function-with_scheduler)
- [`navigation_stack`](#function-navigation_stack)
- [`set_navigation_stack`](#function-set_navigation_stack)
- [`navigate_back`](#function-navigate_back)
- [`set_navigate_back`](#function-set_navigate_back)
- [`navigate`](#function-navigate)
- [`set_navigate`](#function-set_navigate)
- [`navigate_and_reset`](#function-navigate_and_reset)
- [`set_navigate_and_reset`](#function-set_navigate_and_reset)
- [`current_view_model`](#function-current_view_model)
- [`set_current_view_model`](#function-set_current_view_model)
- [`navigation_stack_changed`](#function-navigation_stack_changed)
- [`set_navigation_stack_changed`](#function-set_navigation_stack_changed)
- [`can_navigate_back`](#function-can_navigate_back)
- [`set_can_navigate_back`](#function-set_can_navigate_back)

<a id="function-new"></a>

### new

```rust
fn new() -> Rc<Self>
```

A router with an empty stack, whose navigation notifies on
`RxSchedulers::main_thread_scheduler` (`RoutingState()`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L74)

<a id="function-with_scheduler"></a>

### with_scheduler

```rust
fn with_scheduler(scheduler: Option<Rc<dyn IScheduler>>) -> Rc<Self>
```

A router whose navigation notifies on `scheduler`, or on
`RxSchedulers::main_thread_scheduler` when `None` (`RoutingState(IScheduler?)`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L80)

<a id="function-navigation_stack"></a>

### navigation_stack

```rust
fn navigation_stack(self: &Self) -> NavigationStack
```

The navigation stack, the last view model being the current one (`NavigationStack`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L102)

<a id="function-set_navigation_stack"></a>

### set_navigation_stack

```rust
fn set_navigation_stack(self: &Self, value: NavigationStack)
```

Replaces the navigation stack (`NavigationStack { set; }`). The observables observe the
stack the router has when they are subscribed.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L108)

<a id="function-navigate_back"></a>

### navigate_back

```rust
fn navigate_back(self: &Self) -> NavigateBackCommand
```

Navigates back to the previous view model of the stack, and emits the new current one
(`NavigateBack`). It can execute while the stack holds at least two view models.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L114)

<a id="function-set_navigate_back"></a>

### set_navigate_back

```rust
fn set_navigate_back(self: &Self, value: NavigateBackCommand)
```

Replaces `navigate_back` (its protected setter).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L119)

<a id="function-navigate"></a>

### navigate

```rust
fn navigate(self: &Self) -> NavigateCommand
```

Pushes a view model on the stack, and emits it once the navigation scheduler delivers it
(`Navigate`). Executing it with `None` fails, as upstream fails for `null`.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L125)

<a id="function-set_navigate"></a>

### set_navigate

```rust
fn set_navigate(self: &Self, value: NavigateCommand)
```

Replaces `navigate` (its protected setter).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L130)

<a id="function-navigate_and_reset"></a>

### navigate_and_reset

```rust
fn navigate_and_reset(self: &Self) -> NavigateCommand
```

Replaces the whole stack with a view model, clearing the history of the navigation
(`NavigateAndReset`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L136)

<a id="function-set_navigate_and_reset"></a>

### set_navigate_and_reset

```rust
fn set_navigate_and_reset(self: &Self, value: NavigateCommand)
```

Replaces `navigate_and_reset` (its protected setter).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L141)

<a id="function-current_view_model"></a>

### current_view_model

```rust
fn current_view_model(self: &Self) -> Rc<dyn IObservable<Option<RoutableViewModel>>>
```

The view model on top of the stack: the current one on subscription, then again after
every change of the stack; `None` while the stack is empty (`CurrentViewModel`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L147)

<a id="function-set_current_view_model"></a>

### set_current_view_model

```rust
fn set_current_view_model(self: &Self, value: Rc<dyn IObservable<Option<RoutableViewModel>>>)
```

Replaces `current_view_model` (its protected setter).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L152)

<a id="function-navigation_stack_changed"></a>

### navigation_stack_changed

```rust
fn navigation_stack_changed(self: &Self) -> Rc<dyn IObservable<NavigationStackSnapshot>>
```

A copy of the whole stack after each change of `navigation_stack`,
oldest first; nothing on subscription (`NavigationStackChanged`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L158)

<a id="function-set_navigation_stack_changed"></a>

### set_navigation_stack_changed

```rust
fn set_navigation_stack_changed(self: &Self, value: Rc<dyn IObservable<NavigationStackSnapshot>>)
```

Replaces `navigation_stack_changed` (its protected
setter); `current_view_model` and
`can_navigate_back` follow the replacement.

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L165)

<a id="function-can_navigate_back"></a>

### can_navigate_back

```rust
fn can_navigate_back(self: &Self) -> Rc<dyn IObservable<bool>>
```

Whether there is a view model to go back to, which holds while the stack has at least two:
the current answer on subscription, then each change of it (`CanNavigateBack`).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L171)

<a id="function-set_can_navigate_back"></a>

### set_can_navigate_back

```rust
fn set_can_navigate_back(self: &Self, value: Rc<dyn IObservable<bool>>)
```

Replaces `can_navigate_back` (its protected setter).

[Source](https://github.com/wieslawsoltes/FerroUI/blob/d503df2befa756e681fcdc6250e9552dc7388bea/src/FerroUI.ReactiveUI/routing/routing_state.rs#L176)

## Trait implementations

- `Send`
- `Sync`
- `Freeze`
- `UnsafeUnpin`
- `Unpin`
- `UnwindSafe`
- `RefUnwindSafe`
- [`IReactiveObjectExt`](/docs/0.5.0/api/ferroui-reactiveui/reactive_object/trait-ireactiveobjectext/)
- `Borrow<T>`
- `BorrowMut<T>`
- `Into<U>`
- `From<T>`
- `TryInto<U>`
- `TryFrom<U>`
- `Any`
- [`INotifyPropertyChanged`](/docs/0.5.0/api/ferroui-base/data/model/use-inotifypropertychanged/)
- [`INotifyPropertyChanging`](/docs/0.5.0/api/ferroui-system/component_model/trait-inotifypropertychanging/)
- [`IEnableLogger`](/docs/0.5.0/api/ferroui-splat/logging/trait-ienablelogger/)
- [`IReactiveObject`](/docs/0.5.0/api/ferroui-reactiveui/reactive_object/trait-ireactiveobject/)
- [`IHandleObservableErrors`](/docs/0.5.0/api/ferroui-reactiveui/interfaces/trait-ihandleobservableerrors/)
- `Debug`
- `PartialEq`
- [`RoutingStateMixins`](/docs/0.5.0/api/ferroui-reactiveui/routing/trait-routingstatemixins/)

## Availability

Extracted for `aarch64-apple-darwin`. Cargo features are listed in the [crate index](/docs/0.5.0/api/).
