Struct Router

Source
pub struct Router { /* private fields */ }
Expand description

A struct representing the router for navigation.

Implementationsยง

Sourceยง

impl Router

Source

pub fn new( history: AnyHistory, basename: &'static str, route: &'static str, components: HashMap<&'static str, ComponentInfo>, fetching_routes: HashSet<String>, events: EventListener, error_component: Html, pathname: &'static str, query: Value, as_path: &'static str, subscriptions: Vec<Callback<ComponentInfo>>, component_load_cancel: Callback<()>, ) -> Self

Creates a new router instance.

ยงArguments
  • history - The history instance for navigation.
  • basename - The base URL for the router.
  • route - The default route for the router.
  • components - A mapping of route names to component information.
  • fetching_routes - Set of routes currently being fetched.
  • events - Event listener for handling router events.
  • error_component - The component to display in case of navigation errors.
  • pathname - The current pathname of the router.
  • query - The current query parameters of the router.
  • as_path - The current path as a string.
  • subscriptions - List of callbacks for component information updates.
  • component_load_cancel - Callback for cancelling component loading.
ยงReturns

A new Router instance.

Source

pub fn basename(&self) -> &'static str

Returns the basename of the current router.

Source

pub fn back(&self)

Navigates back by one page.

Source

pub fn forward(&self)

Navigates forward by one page.

Source

pub fn go(&self, delta: isize)

Navigates to a specific page with a delta relative to the current page.

ยงArguments
  • delta - The number of pages to navigate (positive for forward, negative for backward).

See: https://developer.mozilla.org/en-US/docs/Web/API/History/go

Source

pub fn push(&mut self, route: &'static str)

Pushes a route onto the history stack.

ยงArguments
  • route - The route to be pushed.
Source

pub fn replace(&mut self, route: &'static str)

Replaces the current history entry with the provided route.

ยงArguments
  • route - The route to replace the current history entry.
Source

pub fn push_with_state(&mut self, route: &'static str, state: &'static str)

Pushes a route onto the history stack with state.

ยงArguments
  • route - The route to be pushed.
  • state - The state to be associated with the route.
Source

pub fn replace_with_state(&mut self, route: &'static str, state: &'static str)

Replaces the current history entry with the provided route and state.

ยงArguments
  • route - The route to replace the current history entry.
  • state - The state to be associated with the route.
Source

pub fn push_with_query( &mut self, route: &'static str, query: &Value, ) -> NavigationResult<()>

Pushes a route onto the history stack with query parameters.

ยงArguments
  • route - The route to be pushed.
  • query - The query parameters to be associated with the route.
ยงReturns

A NavigationResult indicating the success of the operation.

Source

pub fn push_with_query_and_state( &mut self, route: &'static str, query: &Value, state: &'static str, ) -> NavigationResult<()>

Pushes a route onto the history stack with query parameters and state.

ยงArguments
  • route - The route to be pushed.
  • query - The query parameters to be associated with the route.
  • state - The state to be associated with the route.
ยงReturns

A NavigationResult indicating the success of the operation.

Source

pub fn replace_with_query_and_state( &mut self, route: &'static str, query: &Value, state: Value, ) -> NavigationResult<()>

Replaces the current history entry with the provided route, query parameters, and state.

ยงArguments
  • route - The route to replace the current history entry.
  • query - The query parameters to be associated with the route.
  • state - The state to be associated with the route.
ยงReturns

A NavigationResult indicating the success of the operation.

Source

pub fn kind(&self) -> RouterKind

Returns the kind of the router.

ยงReturns

A RouterKind enum representing the type of the router.

Source

pub fn prefix_basename<'a>(&self, route_s: &'a str) -> Cow<'a, str>

Prefixes the basename to the route.

ยงArguments
  • route_s - The route to prefix with the basename.
ยงReturns

A Cow<'a, str> containing the combined route with the basename.

Source

pub fn strip_basename<'a>(&self, path: Cow<'a, str>) -> Cow<'a, str>

Strips the basename from the path.

ยงArguments
  • path - The path to strip the basename from.
ยงReturns

A Cow<'a, str> containing the path with the basename stripped.

Source

pub fn prefetch(&mut self, url: &'static str)

Prefetches the specified URL by fetching its route information.

ยงArguments
  • url - The URL to prefetch.

Trait Implementationsยง

Sourceยง

impl Clone for Router

Sourceยง

fn clone(&self) -> Router

Returns a duplicate of the value. Read more
1.0.0 ยท Sourceยง

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

Performs copy-assignment from source. Read more
Sourceยง

impl Debug for Router

Sourceยง

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Sourceยง

impl PartialEq for Router

Sourceยง

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 ยท Sourceยง

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

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> Instrument for T

Sourceยง

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Sourceยง

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<T> IntoPropValue<Option<T>> for T

Sourceยง

fn into_prop_value(self) -> Option<T>

Convert self to a value of a Properties struct.
Sourceยง

impl<T> IntoPropValue<T> for T

Sourceยง

fn into_prop_value(self) -> T

Convert self to a value of a Properties struct.
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Sourceยง

impl<T> WithSubscriber for T

Sourceยง

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Sourceยง

impl<Token, Builder, How> AllPropsFor<Builder, How> for Token
where Builder: Buildable<Token>, <Builder as Buildable<Token>>::WrappedToken: HasAllProps<<Builder as Buildable<Token>>::Output, How>,

Sourceยง

impl<T> HasAllProps<(), T> for T