pub struct GoRouter { /* private fields */ }Expand description
The routes, and the stack of pages showing which of them the person has been through.
A cheap handle: clone it into a handler and navigate from there.
Implementations§
Source§impl GoRouter
impl GoRouter
Sourcepub fn initial_location(self, location: impl Into<String>) -> Self
pub fn initial_location(self, location: impl Into<String>) -> Self
Where the router starts. / by default.
Sourcepub fn redirect(
self,
redirect: impl Fn(&GoRouterState) -> Option<String> + 'static,
) -> Self
pub fn redirect( self, redirect: impl Fn(&GoRouterState) -> Option<String> + 'static, ) -> Self
A redirect for every navigation: it is told where it is heading and may answer with
another location, or None to let it through.
It closes over whatever it needs to decide — a handle to the signed-in state, say.
Sourcepub fn error_builder<W: Widget + 'static>(
self,
builder: impl Fn(&BuildContext<'_>, &GoRouterState) -> W + 'static,
) -> Self
pub fn error_builder<W: Widget + 'static>( self, builder: impl Fn(&BuildContext<'_>, &GoRouterState) -> W + 'static, ) -> Self
The page shown when no route answers to a location. A plain “not found” page by default.
Sourcepub fn redirect_limit(self, limit: usize) -> Self
pub fn redirect_limit(self, limit: usize) -> Self
How many redirects in a row are followed before the router gives up and shows the error page. Five by default.
Sourcepub fn refresh_listenable(self, listenable: &impl Listenable) -> Self
pub fn refresh_listenable(self, listenable: &impl Listenable) -> Self
Runs the redirects again whenever listenable changes — the way a sign-in or sign-out
moves the person without anyone having navigated.
Sourcepub fn state(&self) -> Option<GoRouterState>
pub fn state(&self) -> Option<GoRouterState>
The state of the page on top: what its location put in it.
Sourcepub fn locations(&self) -> Vec<String>
pub fn locations(&self) -> Vec<String>
The location of every page in the stack, the one at the bottom first and the one on top last.
Sourcepub fn replaced(&self) -> bool
pub fn replaced(&self) -> bool
Whether the last move swapped the page on top for another — replace
— rather than adding a page, removing one or rebuilding the stack. What an address bar
wants to know, to swap its entry too instead of adding one.
Sourcepub fn location_for(
&self,
name: &str,
params: &[(&str, &str)],
query: &[(&str, &str)],
) -> Option<String>
pub fn location_for( &self, name: &str, params: &[(&str, &str)], query: &[(&str, &str)], ) -> Option<String>
The location of the route called name, with its :parameters filled in and query
appended. None if there is no such route, or a parameter is missing.
Sourcepub fn go(&self, location: impl AsRef<str>)
pub fn go(&self, location: impl AsRef<str>)
Goes to location: the stack becomes the routes that location is made of.
Sourcepub fn go_with_extra(&self, location: impl AsRef<str>, extra: impl Any)
pub fn go_with_extra(&self, location: impl AsRef<str>, extra: impl Any)
go, carrying an object the page can read with
GoRouterState::extra.
Sourcepub fn go_named(
&self,
name: &str,
params: &[(&str, &str)],
query: &[(&str, &str)],
)
pub fn go_named( &self, name: &str, params: &[(&str, &str)], query: &[(&str, &str)], )
Goes to the route called name.
Sourcepub fn push(&self, location: impl AsRef<str>)
pub fn push(&self, location: impl AsRef<str>)
Pushes the page for location on top of what is here.
Sourcepub fn push_with_extra(&self, location: impl AsRef<str>, extra: impl Any)
pub fn push_with_extra(&self, location: impl AsRef<str>, extra: impl Any)
push, carrying an object the page can read with
GoRouterState::extra.
Sourcepub fn push_named(
&self,
name: &str,
params: &[(&str, &str)],
query: &[(&str, &str)],
)
pub fn push_named( &self, name: &str, params: &[(&str, &str)], query: &[(&str, &str)], )
Pushes the route called name.
Sourcepub fn open(&self, location: impl AsRef<str>)
pub fn open(&self, location: impl AsRef<str>)
Goes to a location that came from outside the application: an address typed, a
link followed, the browser’s back button. Like go, except that a
location the router is already at is left alone, and that before anything has been
built there is no page to slide away from, so the router simply starts there.
It is what the shell’s FrusApp hands an address to.
Sourcepub fn replace(&self, location: impl AsRef<str>)
pub fn replace(&self, location: impl AsRef<str>)
Replaces the page on top with the one for location, so going back skips the one it
replaced.
Sourcepub fn pop(&self) -> bool
pub fn pop(&self) -> bool
Removes the page on top. Whether there was one to remove: the last page stays.
Sourcepub fn refresh(&self)
pub fn refresh(&self)
Asks the redirects again about where the top page is. What a
refresh listenable does when it changes.
Sourcepub fn tick(&self, dt: f32) -> bool
pub fn tick(&self, dt: f32) -> bool
Advances the page transition and a back gesture’s settling by dt seconds. Whether
anything is still moving.
Sourcepub fn can_go_back(&self) -> bool
pub fn can_go_back(&self) -> bool
Whether a back gesture can start: there is a page to go back to.
Sourcepub fn back_gesture(&self, progress: f32)
pub fn back_gesture(&self, progress: f32)
A back gesture is under way, progress of the way from 0 to 1.
Sourcepub fn back_gesture_end(&self, velocity: f32)
pub fn back_gesture_end(&self, velocity: f32)
The finger lifted, moving at velocity (fractions per second): the page goes back or
stays, whichever the momentum and the position say.
Sourcepub fn build(&self, cx: &BuildContext<'_>) -> Box<dyn Widget>
pub fn build(&self, cx: &BuildContext<'_>) -> Box<dyn Widget>
The widget for the router’s pages: what an application whose root is a router
builds. It also makes the router reachable from below, with BuildContext::router.