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