Skip to main content

BrowserRouter

Struct BrowserRouter 

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

Browser router that uses the History API.

In WASM, this interfaces with the browser’s history.pushState/replaceState. In non-WASM (tests), this uses an in-memory implementation.

Implementations§

Source§

impl BrowserRouter

Source

pub fn new() -> Self

Create a new browser router.

Source

pub fn pathname(&self) -> String

Get the current pathname.

Source

pub fn search(&self) -> String

Get the current search query string.

Source

pub fn hash(&self) -> String

Get the current hash.

Source

pub fn push(&self, path: &str)

Navigate to a new route, adding to history.

Source

pub fn replace(&self, path: &str)

Replace the current route without adding to history.

Source

pub fn back(&self)

Go back in history.

Source

pub fn forward(&self)

Go forward in history.

Source

pub fn go(&self, delta: i32)

Go to a specific point in history (positive = forward, negative = back).

Source

pub fn history_len(&self) -> usize

Get the history length.

Source

pub fn can_go_back(&self) -> bool

Check if we can go back.

Source

pub fn can_go_forward(&self) -> bool

Check if we can go forward.

Trait Implementations§

Source§

impl Debug for BrowserRouter

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for BrowserRouter

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Router for BrowserRouter

Source§

fn navigate(&self, route: &str)

Navigate to a route.
Source§

fn current_route(&self) -> String

Get the current route.

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> 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<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.