Move the history provider into the context (#3048)
* move history providers into a separate crate * start moving route providers into the renderers * clean up intoroutable * remove into routable * fix router tests * Provide history providers in each renderer * implement nested routers * move the lens out of the history crate * re-export dioxus history trait in the prelude * also re-export the history function * fix history doctests * some light cleanups --------- Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
This commit is contained in:
1 parent
e5a1a62644
commit
281087469a
48 files changed
+875
-1419
No files matched your search
@@ -7,11 +7,23 @@ use std::{
|
||||
|
||||
use url::{ParseError, Url};
|
||||
|
||||
use crate::routable::Routable;
|
||||
use crate::{components::child_router::consume_child_route_mapping, routable::Routable, router};
|
||||
|
||||
impl<R: Routable> From<R> for NavigationTarget {
|
||||
fn from(value: R) -> Self {
|
||||
// If this is a child route, map it to the root route first
|
||||
let mapping = consume_child_route_mapping();
|
||||
match mapping.as_ref() {
|
||||
Some(mapping) => NavigationTarget::Internal(mapping.format_route_as_root_route(value)),
|
||||
// Otherwise, just use the internal route
|
||||
None => NavigationTarget::Internal(value.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A target for the router to navigate to.
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub enum NavigationTarget<R> {
|
||||
pub enum NavigationTarget<R = String> {
|
||||
/// An internal path that the router can navigate to by itself.
|
||||
///
|
||||
/// ```rust
|
||||
@@ -80,6 +92,35 @@ impl<R: Routable> From<R> for NavigationTarget<R> {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for NavigationTarget {
|
||||
fn from(value: &str) -> Self {
|
||||
let router = router();
|
||||
match router.internal_route(value) {
|
||||
true => NavigationTarget::Internal(value.to_string()),
|
||||
false => NavigationTarget::External(value.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<String> for NavigationTarget {
|
||||
fn from(value: String) -> Self {
|
||||
let router = router();
|
||||
match router.internal_route(&value) {
|
||||
true => NavigationTarget::Internal(value),
|
||||
false => NavigationTarget::External(value),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Routable> From<NavigationTarget<R>> for NavigationTarget {
|
||||
fn from(value: NavigationTarget<R>) -> Self {
|
||||
match value {
|
||||
NavigationTarget::Internal(r) => r.into(),
|
||||
NavigationTarget::External(s) => Self::External(s),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Routable> Display for NavigationTarget<R> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
|
||||
Reference in new issue
Block a user