pub struct GlobalRouter { /* private fields */ }Expand description
Global router state accessible from any component.
This is the central routing object stored as a GPUI global. It holds the navigation state, route registry, and orchestrates the navigation pipeline (guards -> middleware -> navigation -> middleware).
Implementations§
Source§impl GlobalRouter
impl GlobalRouter
Sourcepub const fn match_stack(&self) -> &MatchStack
pub const fn match_stack(&self) -> &MatchStack
Get the pre-resolved match stack for the current path.
Outlets call this during render to find their route by depth index. The stack is built once per navigation, so this is O(1).
Sourcepub const fn previous_stack(&self) -> Option<&MatchStack>
Available on crate feature transition only.
pub const fn previous_stack(&self) -> Option<&MatchStack>
transition only.Get the previous match stack (for transition animations).
Sourcepub fn add_route(&mut self, route: Route)
pub fn add_route(&mut self, route: Route)
Register a route and re-resolve the match stack.
If the route has a name, it is
also registered in the NamedRouteRegistry for URL generation via
url_for.
Sourcepub fn push(&mut self, path: String, cx: &App) -> NavigationResult
pub fn push(&mut self, path: String, cx: &App) -> NavigationResult
Navigate to a path, running the full guard/middleware pipeline.
Pipeline:
- Collect guards from matched route (+ ancestors)
- Check guards — if any denies/redirects, navigation is blocked
- Run
before_navigationmiddleware - Perform actual navigation
- Run
after_navigationmiddleware
Sourcepub fn replace(&mut self, path: String, cx: &App) -> NavigationResult
pub fn replace(&mut self, path: String, cx: &App) -> NavigationResult
Replace current path, running the full guard/middleware pipeline.
Sourcepub fn back(&mut self, cx: &App) -> Option<NavigationResult>
pub fn back(&mut self, cx: &App) -> Option<NavigationResult>
Go back in history, checking guards on the target route.
Sourcepub fn forward(&mut self, cx: &App) -> Option<NavigationResult>
pub fn forward(&mut self, cx: &App) -> Option<NavigationResult>
Go forward in history, checking guards on the target route.
Sourcepub fn push_with_state(
&mut self,
path: String,
state: HistoryState,
cx: &App,
) -> NavigationResult
pub fn push_with_state( &mut self, path: String, state: HistoryState, cx: &App, ) -> NavigationResult
Push a new path with associated HistoryState data, running the full pipeline.
Allows attaching arbitrary key-value state (scroll position, form data, etc.) to the history entry. The pipeline (guards, middleware) runs first; state is only attached if navigation succeeds.
Sourcepub fn replace_with_state(
&mut self,
path: String,
state: HistoryState,
cx: &App,
) -> NavigationResult
pub fn replace_with_state( &mut self, path: String, state: HistoryState, cx: &App, ) -> NavigationResult
Replace current path with associated HistoryState data, running the full pipeline.
Sourcepub fn current_entry(&self) -> &HistoryEntry
pub fn current_entry(&self) -> &HistoryEntry
Return the current HistoryEntry (path + optional state data).
Sourcepub fn push_named(
&mut self,
name: &str,
params: &RouteParams,
cx: &App,
) -> Option<NavigationResult>
pub fn push_named( &mut self, name: &str, params: &RouteParams, cx: &App, ) -> Option<NavigationResult>
Navigate to a named route, resolving the URL from params.
Returns None if the name is not registered.
Sourcepub fn url_for(&self, name: &str, params: &RouteParams) -> Option<String>
pub fn url_for(&self, name: &str, params: &RouteParams) -> Option<String>
Generate a URL for a named route by substituting params into its pattern.
Returns None if the name is not registered.
Sourcepub fn current_path(&self) -> &str
pub fn current_path(&self) -> &str
Return the current navigation path.
Sourcepub fn current_match(&mut self) -> Option<RouteMatch>
pub fn current_match(&mut self) -> Option<RouteMatch>
Get current route match (with caching, requires mutable).
Sourcepub fn current_match_immutable(&self) -> Option<RouteMatch>
pub fn current_match_immutable(&self) -> Option<RouteMatch>
Get current route match (immutable, no caching).
Sourcepub fn current_route(&self) -> Option<&Arc<Route>>
pub fn current_route(&self) -> Option<&Arc<Route>>
Get the current matched Route.
Sourcepub const fn can_go_back(&self) -> bool
pub const fn can_go_back(&self) -> bool
Check if can go back.
Sourcepub fn can_go_forward(&self) -> bool
pub fn can_go_forward(&self) -> bool
Check if can go forward.
Sourcepub fn state_mut(&mut self) -> &mut RouterState
pub fn state_mut(&mut self) -> &mut RouterState
Get mutable state reference.
Sourcepub const fn state(&self) -> &RouterState
pub const fn state(&self) -> &RouterState
Get state reference.
Sourcepub fn nested_cache_mut(&mut self) -> &mut RouteCache
Available on crate feature cache only.
pub fn nested_cache_mut(&mut self) -> &mut RouteCache
cache only.Get nested route cache (mutable).
Sourcepub const fn cache_stats(&self) -> &CacheStats
Available on crate feature cache only.
pub const fn cache_stats(&self) -> &CacheStats
cache only.Get nested route cache statistics.
Sourcepub fn set_error_handlers(&mut self, handlers: ErrorHandlers)
pub fn set_error_handlers(&mut self, handlers: ErrorHandlers)
Set custom error handlers for 404 and navigation errors.
Sourcepub const fn error_handlers(&self) -> &ErrorHandlers
pub const fn error_handlers(&self) -> &ErrorHandlers
Get a reference to the current error handlers.
Sourcepub fn get_cached_component(&self, key: &str) -> Option<&AnyView>
pub fn get_cached_component(&self, key: &str) -> Option<&AnyView>
Get a cached component view by key.
Sourcepub fn cache_component(&mut self, key: String, view: AnyView)
pub fn cache_component(&mut self, key: String, view: AnyView)
Store a component view in the cache, evicting the oldest entry if full.
Sourcepub fn set_next_transition(&mut self, transition: Transition)
Available on crate feature transition only.
pub fn set_next_transition(&mut self, transition: Transition)
transition only.Set transition for the next navigation.
Sourcepub fn take_next_transition(&mut self) -> Option<Transition>
Available on crate feature transition only.
pub fn take_next_transition(&mut self) -> Option<Transition>
transition only.Get and consume the next transition override.
Sourcepub const fn has_next_transition(&self) -> bool
Available on crate feature transition only.
pub const fn has_next_transition(&self) -> bool
transition only.Check if there’s a transition override set.
Sourcepub fn clear_next_transition(&mut self)
Available on crate feature transition only.
pub fn clear_next_transition(&mut self)
transition only.Clear transition override.
Sourcepub fn push_with_transition(
&mut self,
path: String,
transition: Transition,
cx: &App,
) -> NavigationResult
Available on crate feature transition only.
pub fn push_with_transition( &mut self, path: String, transition: Transition, cx: &App, ) -> NavigationResult
transition only.Navigate with a specific transition.
Sourcepub fn replace_with_transition(
&mut self,
path: String,
transition: Transition,
cx: &App,
) -> NavigationResult
Available on crate feature transition only.
pub fn replace_with_transition( &mut self, path: String, transition: Transition, cx: &App, ) -> NavigationResult
transition only.Replace with a specific transition.
Trait Implementations§
Source§impl Clone for GlobalRouter
impl Clone for GlobalRouter
Source§fn clone(&self) -> GlobalRouter
fn clone(&self) -> GlobalRouter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for GlobalRouter
impl Default for GlobalRouter
impl Global for GlobalRouter
Auto Trait Implementations§
impl !RefUnwindSafe for GlobalRouter
impl !Send for GlobalRouter
impl !Sync for GlobalRouter
impl !UnwindSafe for GlobalRouter
impl Freeze for GlobalRouter
impl Unpin for GlobalRouter
impl UnsafeUnpin for GlobalRouter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> ReadGlobal for Twhere
T: Global,
impl<T> ReadGlobal for Twhere
T: Global,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().