Router
QuickGUI コアのルーティングを QuickGUI UI に投影し、ネストされたレイアウトと上限付きメモリ履歴を提供します。
デモを読み込み中…
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"),
}#インポート
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"),
}#構成
RouterRouteDefinitionRouteDefinition::layoutRouter::pushRouter::matched
#API リファレンス
項目を展開すると説明と完全なシグネチャが表示されます。ダッシュは宣言に既定値が記載されていないことを示します。
Router
ソースを見る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—
matchedpub fn matched(&self) -> Option<&RouteMatch>—
history_indexpub fn history_index(&self) -> usize—
history_lengthpub fn history_length(&self) -> usize—
can_go_backpub fn can_go_back(&self) -> bool—
can_go_forwardpub fn can_go_forward(&self) -> bool—
snapshotpub 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—
forwardpub 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>>) -> SelfDeclare 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ソースを見る