pub struct Nav<'f> { /* private fields */ }Expand description
The router, as seen by a view: navigating, loading, shallow routing and blocking.
An extractor: add a nav: Nav argument to any view. It is Copy, so it can be used in
nested closures. Requests are queued and applied after the frame.
Implementations§
Sourcepub fn url(&self) -> &'f str
pub fn url(&self) -> &'f str
The url of the current history entry. Differs from the page’s
Request after Nav::push_state / Nav::replace_state with a
new url.
Sourcepub fn fragment(&self) -> Option<&'f str>
pub fn fragment(&self) -> Option<&'f str>
The #fragment of Nav::url, without the #, e.g. install for /docs#install.
The fragment never affects which page is shown or its loads: going to another fragment of the current url only adds a history entry, like shallow routing. The page decides what it means, e.g. which section to scroll to.
Sourcepub fn is_active(&self, href: &str) -> bool
pub fn is_active(&self, href: &str) -> bool
Whether href is the current path, or (for anything but /) a parent of it. The path
is Nav::url’s, so it follows shallow routing. Queries and fragments are ignored.
Sourcepub fn is_outgoing(&self) -> bool
pub fn is_outgoing(&self) -> bool
Whether this is the previous page, rendered while a ViewTransition
animates it out. Its Ui is disabled (without looking so), and its navigation calls are
ignored. Skip things that live outside the page’s Ui (windows, modals, popups), which
the transition can’t fade, clip or disable.
Sourcepub fn goto(&self, url: impl Into<String>)
pub fn goto(&self, url: impl Into<String>)
Navigates to url, adding a history entry.
The current page stays visible until all hooks and load handlers of the new route finished.
Going to the current url does nothing (the page keeps its state), unless
GotoOptions::invalidate_all asks for a reload. Going to the url that is already
loading, with the same options, keeps that navigation going, so a view may ask for it
every frame until it is done.
Sourcepub fn replace(&self, url: impl Into<String>)
pub fn replace(&self, url: impl Into<String>)
Navigates to url, replacing the current history entry. Like Nav::goto, going to the
current url does nothing, unless GotoOptions::invalidate_all asks for a reload.
pub fn back(&self)
pub fn forward(&self)
pub fn can_go_back(&self) -> bool
pub fn can_go_forward(&self) -> bool
Sourcepub fn link(
&self,
ui: &mut Ui,
text: impl Into<WidgetText>,
href: &str,
) -> Response
pub fn link( &self, ui: &mut Ui, text: impl Into<WidgetText>, href: &str, ) -> Response
A hyperlink that navigates within the app. Preloads the target while hovered, unless disabled.
A selectable label that is highlighted when href is active.
Sourcepub fn follow(&self, response: &Response, href: &str)
pub fn follow(&self, response: &Response, href: &str)
Makes any widget behave like a link to href: a click navigates there,
hovering preloads it and lets the browser show it (see BrowserHistory::link_preview),
which then also opens Ctrl/Cmd/Shift-clicks in a new tab.
fn card(ui: &mut egui::Ui, nav: Nav, title: &str, href: &str) {
let response = egui::Frame::group(ui.style())
.show(ui, |ui| ui.heading(title))
.response
.interact(egui::Sense::click());
nav.follow(&response, href);
}Sourcepub fn is_loading(&self) -> bool
pub fn is_loading(&self) -> bool
Whether a navigation is in progress.
Sourcepub fn loading_url(&self) -> Option<String>
pub fn loading_url(&self) -> Option<String>
The url currently being loaded, if any.
Sourcepub fn preload(&self, url: impl Into<String>)
pub fn preload(&self, url: impl Into<String>)
Starts loading url (hooks and loads) in the background, so that navigating there is
instant. Preloads are dropped once any navigation finishes.
Sourcepub fn invalidate(&self, key: impl Into<String>)
pub fn invalidate(&self, key: impl Into<String>)
Sourcepub fn invalidate_all(&self)
pub fn invalidate_all(&self)
Reruns all loads of the current page, and refetches all queries.
Sourcepub fn push_state<T: Any>(&self, url: impl Into<String>, state: T)
pub fn push_state<T: Any>(&self, url: impl Into<String>, state: T)
Adds a history entry with url ("" keeps the current url) and attaches state to it,
without running hooks or loads. The page stays as it is and can read the state with the
HistoryState extractor.
Going back and forward between entries of the same page only swaps the page state.
Entries of a page that is no longer shown are loaded normally, and get their state back.
A browser reload loses all page state, so url should also work on its own, e.g. for a
photo opened in a modal, the photo’s own page.
Sourcepub fn replace_state<T: Any>(&self, url: impl Into<String>, state: T)
pub fn replace_state<T: Any>(&self, url: impl Into<String>, state: T)
Like Nav::push_state, but replaces the state (and url) of the current entry.
Sourcepub fn replace_url(&self, url: impl Into<String>)
pub fn replace_url(&self, url: impl Into<String>)
Changes the url of the current entry, keeping its state: to keep the address in step with
the page (another day in a calendar, another tab) without a navigation. Like
Nav::replace_state, the url should also work on its own.
Sourcepub fn clear_history_state(&self)
pub fn clear_history_state(&self)
Removes the state of the current entry, keeping its url.
Sourcepub fn set_title(&self, title: impl Into<String>)
pub fn set_title(&self, title: impl Into<String>)
Sets the title of the browser tab, or natively of the window. Call it every frame, like
Nav::block_navigation: the innermost view that does wins, so a page’s title replaces
its layouts’, and a root layout can set the default. When no view sets one, the title stays
as it was. See RouterApp::title.
Call every frame while leaving the page would lose something (e.g. unsaved changes).
Navigations away from the page (links, goto, back/forward) are then held back until
you confirm or cancel them;
see Nav::blocked_navigation. Shallow routing and invalidation are not affected.
Closing the window is held back too. Natively, it is a blocked navigation like the others,
of kind NavigationKind::Leave; once confirmed, the window
closes. In the browser, closing or reloading the tab shows the browser’s own prompt
instead, and the page gets no blocked navigation.
The navigation being held back, to ask the user what to do.
Lets the blocked navigation happen.
Drops the blocked navigation.
Trait Implementations§
Auto Trait Implementations§
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more