Skip to main content

GoRouter

Struct GoRouter 

Source
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

Source

pub fn new(routes: Vec<GoRoute>) -> Self

A router over routes, starting at /.

Source

pub fn initial_location(self, location: impl Into<String>) -> Self

Where the router starts. / by default.

Source

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.

Source

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.

Source

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.

Source

pub fn animate(self, animate: bool) -> Self

Whether a page slides in and out. On by default.

Source

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.

Source

pub fn location(&self) -> String

The location of the page on top.

Source

pub fn state(&self) -> Option<GoRouterState>

The state of the page on top: what its location put in it.

Source

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.

Source

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.

Source

pub fn depth(&self) -> usize

How many pages the stack holds.

Source

pub fn can_pop(&self) -> bool

Whether there is a page beneath the top to go back to.

Source

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.

Source

pub fn go(&self, location: impl AsRef<str>)

Goes to location: the stack becomes the routes that location is made of.

Source

pub fn go_with_extra(&self, location: impl AsRef<str>, extra: impl Any)

go, carrying an object the page can read with GoRouterState::extra.

Source

pub fn go_named( &self, name: &str, params: &[(&str, &str)], query: &[(&str, &str)], )

Goes to the route called name.

Source

pub fn push(&self, location: impl AsRef<str>)

Pushes the page for location on top of what is here.

Source

pub fn push_with_extra(&self, location: impl AsRef<str>, extra: impl Any)

push, carrying an object the page can read with GoRouterState::extra.

Source

pub fn push_named( &self, name: &str, params: &[(&str, &str)], query: &[(&str, &str)], )

Pushes the route called name.

Source

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.

Source

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.

Source

pub fn pop(&self) -> bool

Removes the page on top. Whether there was one to remove: the last page stays.

Source

pub fn refresh(&self)

Asks the redirects again about where the top page is. What a refresh listenable does when it changes.

Source

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.

Source

pub fn can_go_back(&self) -> bool

Whether a back gesture can start: there is a page to go back to.

Source

pub fn back_gesture(&self, progress: f32)

A back gesture is under way, progress of the way from 0 to 1.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for GoRouter

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<Msg> IntoMsg<Msg> for Msg

Source§

fn defer(work: impl Fn() -> Msg + 'static) -> Msg

The message that stands for work’s result.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.