本文へスキップ

Router

QuickGUI コアのルーティングを QuickGUI UI に投影し、ネストされたレイアウトと上限付きメモリ履歴を提供します。

デモを読み込み中…

#インポート

quickgui から Router をインポートします。

use quickgui::*;

#使い方

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"),
}

#構成

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

#API リファレンス

項目を展開すると説明と完全なシグネチャが表示されます。ダッシュは宣言に既定値が記載されていないことを示します。

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
ソースを見る
matchedpub fn matched(&self) -> Option<&RouteMatch>—

Configures matched for this part.

pub fn matched(&self) -> Option<&RouteMatch>
ソースを見る
history_indexpub fn history_index(&self) -> usize—

Configures history index for this part.

pub fn history_index(&self) -> usize
ソースを見る
history_lengthpub fn history_length(&self) -> usize—

Configures history length for this part.

pub fn history_length(&self) -> usize
ソースを見る
can_go_backpub fn can_go_back(&self) -> bool—

Configures can go back for this part.

pub fn can_go_back(&self) -> bool
ソースを見る
can_go_forwardpub fn can_go_forward(&self) -> bool—

Configures can go forward for this part.

pub fn can_go_forward(&self) -> bool
ソースを見る
snapshotpub fn snapshot(&self) -> RouterSnapshot—

Configures snapshot for this part.

pub fn snapshot(&self) -> RouterSnapshot
ソースを見る
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>
ソースを見る
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>
ソースを見る
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>
ソースを見る
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
ソースを見る
backpub fn back(&mut self) -> bool—

Configures back for this part.

pub fn back(&mut self) -> bool
ソースを見る
forwardpub fn forward(&mut self) -> bool—

Configures forward for this part.

pub fn forward(&mut self) -> bool
ソースを見る
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>
ソースを見る

RouteDefinition

ソースを見る
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
ソースを見る
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
ソースを見る
idpub fn id(&self) -> &str—

Configures id for this part.

pub fn id(&self) -> &str
ソースを見る
pathpub fn path(&self) -> Option<&str>—

Configures path for this part.

pub fn path(&self) -> Option<&str>
ソースを見る
parent_idpub fn parent_id(&self) -> Option<&str>—

Configures parent id for this part.

pub fn parent_id(&self) -> Option<&str>
ソースを見る