Skip to content
FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    Navigate between views

    A navigation model owns where the application is and how users return. Separate that model from the presentation of a navigation bar, tabs, or a side pane.

    For a small settings screen, the control can own the selection without a route service:

    <TabControl xmlns="https://github.com/ferroui">
    <TabItem Header="General">
    <StackPanel Margin="16" Spacing="8">
    <TextBlock Text="General settings" />
    <CheckBox Content="Show tips at startup" />
    </StackPanel>
    </TabItem>
    <TabItem Header="Account">
    <TextBlock Margin="16" Text="Account settings" />
    </TabItem>
    </TabControl>

    Switch tabs with both pointer and keyboard. Move each page into a reusable UserControl as it grows. If a destination needs a record ID, browser URL, or back stack, introduce an explicit navigation model rather than treating tab positions as routes.

    Use a small content host when the application has a few independent views. Use Frame and page navigation for a stack/history workflow. Use a NavigationView when the shell needs a top-level navigation structure. Declarative applications use the router of ferroui-view; MVVM applications use the routing state of ReactiveUI.

    A navigation control’s selection is not automatically your application’s route. Synchronize them deliberately, including back navigation and programmatic changes.

    Decide whether returning to a page recreates it or restores an existing view model. A details page may need a stable record identifier rather than a reference to a particular control instance. Keep persisted application state out of transient view objects.

    The browser has its own history and URL. If users must bookmark a location, map routes to that URL explicitly. A native page stack alone does not establish a browser deep-link contract.

    Cancel obsolete loads, release subscriptions, and stop timers when leaving a view. If views are intentionally cached, distinguish being retained from being active. A cached view should not continue expensive work merely because an object still owns it.

    Test forward, back, repeated navigation to the same destination, missing records, and errors during asynchronous page loading.

    In declarative Rust, router(initial, routes) shows the view of the first matching route and gives the components below a Router handle:

    use ferroui_view::prelude::*;
    #[component(rerender)]
    fn Shell() -> Element {
    let routes = vec![
    route("/", |_| rsx! { Home {} }),
    route("/people/:id", |m| rsx! { Person { id: m.param("id").unwrap_or_default().to_string() } }),
    route("*", |m| rsx! { NotFound { path: m.path().to_string() } }),
    ];
    rsx! { Grid { {router("/", routes)} } }
    }
    #[component(rerender)]
    fn Home() -> Element {
    let router = use_router();
    rsx! { Button { on_click: move |_| router.navigate("/people/42"), "Open person 42" } }
    }

    Home, Person, and NotFound are the application’s components. The stack holds paths, so a details page receives a record identifier, not a control. navigate_back, navigate_and_reset, can_go_back, and current complete the handle; lists, async data & routing describes the patterns. Another route mounts its view anew and removes the previous view with its state, so state that outlives navigation lives above the router.

    ReactiveUI applications can let a screen own RoutingState and host its current page with this view fragment:

    <rxui:RoutedViewHost xmlns="https://github.com/ferroui"
    xmlns:rxui="using:ReactiveUI.FerroUI"
    Router="{ReflectionBinding Router}">
    <rxui:RoutedViewHost.DefaultContent>
    <TextBlock Text="Select a page to begin." />
    </rxui:RoutedViewHost.DefaultContent>
    </rxui:RoutedViewHost>

    Initialize ReactiveUI, register its markup types and your view mappings, and expose Router on the screen’s data context. navigate, navigate_and_reset, and navigate_back are commands; subscribe to the returned execution observable to execute them. See the complete screen view model for construction and routing errors.

    Switch between the views with pointer and keyboard. This example demonstrates local tab selection without a route service.

    Related viewsFerroUI · 0.5.0
    Try it for yourself

    Real controls, running in WebAssembly.
    The runtime downloads when you press Run.

    Shared runtime · 9.8 MB compressed · cached across examples
    Download project
    <TabControl xmlns="https://github.com/ferroui">
    <TabItem Header="Overview"><TextBlock Margin="16" Text="The big picture." /></TabItem>
    <TabItem Header="Details"><TextBlock Margin="16" Text="A closer look." /></TabItem>
    </TabControl>
    Ready to explore