Skip to content

Router

A QuickGUI UI projection of QuickGUI core routing with nested layouts and bounded memory history.

Loading interactive demo…

#Import

Import Router from quickgui.

use quickgui::*;

#Usage

let mut router = Router::new(
    [
        RouteDefinition::new("home", "/"),
        RouteDefinition::new("settings", "/settings"),
    ],
    "/",
)?;
match router.matched().and_then(|matched| matched.route_ids().last().map(|id| id.as_ref())) {
    Some("settings") => text("Settings"),
    _ => button().on_click(open_settings).child("Settings"),
}

#Anatomy

  • Router
  • RouteDefinition
  • RouteDefinition::layout
  • Router::push
  • Router::matched

#API reference

Expand an entry for its description and complete signature. A dash means no declaration default is documented.

pub fn new( definitions: impl IntoIterator<Item = RouteDefinition>, initial_destination: impl AsRef<str>, ) -> Result<Self, RouterError>

Compile a declarative route tree and begin its memory history at `initial_destination`.

locationpub fn location(&self) -> &RouteLocation—

Configures location for this part.

pub fn location(&self) -> &RouteLocation
View source
matchedpub fn matched(&self) -> Option<&RouteMatch>—

Configures matched for this part.

pub fn matched(&self) -> Option<&RouteMatch>
View source
history_indexpub fn history_index(&self) -> usize—

Configures history index for this part.

pub fn history_index(&self) -> usize
View source
history_lengthpub fn history_length(&self) -> usize—

Configures history length for this part.

pub fn history_length(&self) -> usize
View source
can_go_backpub fn can_go_back(&self) -> bool—

Configures can go back for this part.

pub fn can_go_back(&self) -> bool
View source
can_go_forwardpub fn can_go_forward(&self) -> bool—

Configures can go forward for this part.

pub fn can_go_forward(&self) -> bool
View source
snapshotpub fn snapshot(&self) -> RouterSnapshot—

Configures snapshot for this part.

pub fn snapshot(&self) -> RouterSnapshot
View source
resolvepub fn resolve(&self, destination: &str) -> Result<RouteLocation, RouterError>—

Resolve an absolute, relative, query-only, or fragment-only destination without mutating.

pub fn resolve(&self, destination: &str) -> Result<RouteLocation, RouterError>
View source
pushpub fn push(&mut self, destination: &str) -> Result<(), RouterError>—

Append one location, discard forward entries, and select the new route match.

pub fn push(&mut self, destination: &str) -> Result<(), RouterError>
View source
replacepub fn replace(&mut self, destination: &str) -> Result<bool, RouterError>—

Replace the current location without changing history length. Returns whether the normalized location changed.

pub fn replace(&mut self, destination: &str) -> Result<bool, RouterError>
View source
gopub fn go(&mut self, delta: isize) -> bool—

Traverse memory history, clamping an oversized delta to the first or last entry.

pub fn go(&mut self, delta: isize) -> bool
View source
backpub fn back(&mut self) -> bool—

Configures back for this part.

pub fn back(&mut self) -> bool
View source
forwardpub fn forward(&mut self) -> bool—

Configures forward for this part.

pub fn forward(&mut self) -> bool
View source
is_activepub fn is_active(&self, destination: &str, end: bool) -> Result<bool, RouterError>—

Whether `destination` resolves to the current pathname. With `end == false`, descendants also count as active on a segment boundary. Query and fragment differences do not affect active state.

pub fn is_active(&self, destination: &str, end: bool) -> Result<bool, RouterError>
View source

RouteDefinition

View source
pub fn new(id: impl Into<Arc<str>>, path: impl Into<Arc<str>>) -> Self

Declare a route that participates in path matching.

layoutpub fn layout(id: impl Into<Arc<str>>) -> Self—

Declare a pathless layout that wraps its matched descendants.

pub fn layout(id: impl Into<Arc<str>>) -> Self
View source
parentpub fn parent(mut self, parent_id: impl Into<Arc<str>>) -> Self—

Attach this route to a declared parent. Parents may appear before or after their children.

pub fn parent(mut self, parent_id: impl Into<Arc<str>>) -> Self
View source
idpub fn id(&self) -> &str—

Configures id for this part.

pub fn id(&self) -> &str
View source
pathpub fn path(&self) -> Option<&str>—

Configures path for this part.

pub fn path(&self) -> Option<&str>
View source
parent_idpub fn parent_id(&self) -> Option<&str>—

Configures parent id for this part.

pub fn parent_id(&self) -> Option<&str>
View source