跳到正文

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>
查看源码