pub trait History {
// Required methods
fn current_route(&self) -> String;
fn go_back(&self);
fn go_forward(&self);
fn push(&self, route: String);
fn replace(&self, path: String);
// Provided methods
fn current_prefix(&self) -> Option<String> { ... }
fn can_go_back(&self) -> bool { ... }
fn can_go_forward(&self) -> bool { ... }
fn external(&self, url: String) -> bool { ... }
fn updater(&self, callback: Arc<dyn Fn() + Sync + Send>) { ... }
fn include_prevent_default(&self) -> bool { ... }
}Required Methods§
Sourcefn current_route(&self) -> String
fn current_route(&self) -> String
Get the path of the current URL.
Must start with /. Must not contain the prefix.
#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
#[route("/")]
Index {},
#[route("/some-other-page")]
OtherPage {},
}
let mut history = dioxus::history::MemoryHistory::default();
assert_eq!(history.current_route(), "/");
history.push(Route::OtherPage {}.to_string());
assert_eq!(history.current_route(), "/some-other-page");Sourcefn go_back(&self)
fn go_back(&self)
Go back to a previous page.
If a [HistoryProvider] cannot go to a previous page, it should do nothing. This method
might be called, even if can_go_back returns false.
#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
#[route("/")]
Index {},
#[route("/some-other-page")]
OtherPage {},
}
let mut history = dioxus::history::MemoryHistory::default();
assert_eq!(history.current_route(), "/");
history.go_back();
assert_eq!(history.current_route(), "/");
history.push(Route::OtherPage {}.to_string());
assert_eq!(history.current_route(), "/some-other-page");
history.go_back();
assert_eq!(history.current_route(), "/");Sourcefn go_forward(&self)
fn go_forward(&self)
Go forward to a future page.
If a [HistoryProvider] cannot go to a previous page, it should do nothing. This method
might be called, even if can_go_forward returns false.
#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
#[route("/")]
Index {},
#[route("/some-other-page")]
OtherPage {},
}
let mut history = dioxus::history::MemoryHistory::default();
history.push(Route::OtherPage {}.to_string());
assert_eq!(history.current_route(), Route::OtherPage {}.to_string());
history.go_back();
assert_eq!(history.current_route(), Route::Index {}.to_string());
history.go_forward();
assert_eq!(history.current_route(), Route::OtherPage {}.to_string());Sourcefn push(&self, route: String)
fn push(&self, route: String)
Go to another page.
This should do three things:
- Merge the current URL with the
pathparameter (which may also include a query part). - Remove the previous URL to the navigation history.
- Clear the navigation future.
#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
#[route("/")]
Index {},
#[route("/some-other-page")]
OtherPage {},
}
let mut history = dioxus::history::MemoryHistory::default();
assert_eq!(history.current_route(), Route::Index {}.to_string());
history.push(Route::OtherPage {}.to_string());
assert_eq!(history.current_route(), Route::OtherPage {}.to_string());
assert!(history.can_go_back());Sourcefn replace(&self, path: String)
fn replace(&self, path: String)
Replace the current page with another one.
This should merge the current URL with the path parameter (which may also include a query
part). In contrast to the push function, the navigation history and future should stay
untouched.
#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
#[route("/")]
Index {},
#[route("/some-other-page")]
OtherPage {},
}
let mut history = dioxus::history::MemoryHistory::default();
assert_eq!(history.current_route(), Route::Index {}.to_string());
history.replace(Route::OtherPage {}.to_string());
assert_eq!(history.current_route(), Route::OtherPage {}.to_string());
assert!(!history.can_go_back());Provided Methods§
Sourcefn current_prefix(&self) -> Option<String>
fn current_prefix(&self) -> Option<String>
Get the current path prefix of the URL.
Not all [HistoryProvider]s need a prefix feature. It is meant for environments where a
dioxus-router-core-routed application is not running on /. The [HistoryProvider] is responsible
for removing the prefix from the dioxus-router-core-internal path, and also for adding it back in
during navigation. This functions value is only used for creating hrefs (e.g. for SSR or
display (but not navigation) in a web app).
Sourcefn can_go_back(&self) -> bool
fn can_go_back(&self) -> bool
Check whether there is a previous page to navigate back to.
If a [HistoryProvider] cannot know this, it should return true.
#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
#[route("/")]
Index {},
#[route("/other")]
Other {},
}
let mut history = dioxus::history::MemoryHistory::default();
assert_eq!(history.can_go_back(), false);
history.push(Route::Other {}.to_string());
assert_eq!(history.can_go_back(), true);Sourcefn can_go_forward(&self) -> bool
fn can_go_forward(&self) -> bool
Check whether there is a future page to navigate forward to.
If a [HistoryProvider] cannot know this, it should return true.
#[derive(Clone, Routable, Debug, PartialEq)]
enum Route {
#[route("/")]
Index {},
#[route("/some-other-page")]
OtherPage {},
}
let mut history = dioxus::history::MemoryHistory::default();
assert_eq!(history.can_go_forward(), false);
history.push(Route::OtherPage {}.to_string());
assert_eq!(history.can_go_forward(), false);
history.go_back();
assert_eq!(history.can_go_forward(), true);Sourcefn updater(&self, callback: Arc<dyn Fn() + Sync + Send>)
fn updater(&self, callback: Arc<dyn Fn() + Sync + Send>)
Provide the [HistoryProvider] with an update callback.
Some [HistoryProvider]s may receive URL updates from outside the router. When such
updates are received, they should call callback, which will cause the router to update.
Sourcefn include_prevent_default(&self) -> bool
fn include_prevent_default(&self) -> bool
Whether the router should include the legacy prevent default attribute instead of the new prevent default method. This should only be used by liveview.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".