Expand description
Routing
High-level routing utilities for Freya applications. This crate provides
components like outlet and router, hooks such as use_route, and the
Navigator context to programmatically interact with navigation state.
§Example
A minimal router that switches between two routes. See examples/feature_router.rs
for a runnable demo.
use freya::prelude::*;
use freya_router::prelude::*;
fn app() -> impl IntoElement {
router::<Route>(|| RouterConfig::default().with_initial_path(Route::Home))
}
#[derive(PartialEq)]
struct Layout;
impl Component for Layout {
fn render(&self) -> impl IntoElement {
rect().center().expanded().child(outlet::<Route>())
}
}
#[derive(PartialEq)]
struct Home;
impl Component for Home {
fn render(&self) -> impl IntoElement {
Link::new(Route::Settings).child("Go Settings")
}
}
#[derive(PartialEq)]
struct Settings;
impl Component for Settings {
fn render(&self) -> impl IntoElement {
Link::new(Route::Home).child("Go Home")
}
}
#[derive(Routable, Clone, PartialEq)]
#[rustfmt::skip]
pub enum Route {
#[layout(Layout)]
#[route("/")]
Home,
#[route("/settings")]
Settings,
}Modules§
- components
- Components interacting with the router.
- hooks
- Hooks for interacting with the router in components.
- navigation
- Types pertaining to navigation.
- prelude
- A collection of useful items most applications might need.
- routable
- Routable