fix external router examples

This commit is contained in:
Evan Almloff committed 2023-06-01 14:10:33 -05:00
1 parent 45a004bf74
commit 07446386e6
7 files changed
+157 -133

No files matched your search

+4 -6
View File
@@ -5,13 +5,13 @@ use std::{cell::RefCell, str::FromStr};
use crate::{
prelude::{GenericOutlet, GenericRouterContext},
routable::Routable,
router_cfg::RouterConfiguration,
router_cfg::RouterConfig,
};
/// The config for [`GenericRouter`].
pub struct RouterConfigFactory<R: Routable> {
#[allow(clippy::type_complexity)]
config: RefCell<Option<Box<dyn FnOnce() -> RouterConfiguration<R>>>>,
config: RefCell<Option<Box<dyn FnOnce() -> RouterConfig<R>>>>,
}
impl<R: Routable> Default for RouterConfigFactory<R>
@@ -19,13 +19,11 @@ where
<R as FromStr>::Err: std::fmt::Display,
{
fn default() -> Self {
Self::from(RouterConfiguration::default)
Self::from(RouterConfig::default)
}
}
impl<R: Routable, F: FnOnce() -> RouterConfiguration<R> + 'static> From<F>
for RouterConfigFactory<R>
{
impl<R: Routable, F: FnOnce() -> RouterConfig<R> + 'static> From<F> for RouterConfigFactory<R> {
fn from(value: F) -> Self {
Self {
config: RefCell::new(Some(Box::new(value))),
+4 -6
View File
@@ -7,7 +7,7 @@ use dioxus::prelude::*;
use crate::{
history::HistoryProvider, navigation::NavigationTarget, routable::Routable,
router_cfg::RouterConfiguration,
router_cfg::RouterConfig,
};
/// An error that can occur when navigating.
@@ -15,7 +15,8 @@ use crate::{
pub struct ExternalNavigationFailure(String);
/// A function the router will call after every routing update.
pub(crate) type RoutingCallback<R> = Arc<dyn Fn(GenericRouterContext<R>) -> Option<NavigationTarget<R>>>;
pub(crate) type RoutingCallback<R> =
Arc<dyn Fn(GenericRouterContext<R>) -> Option<NavigationTarget<R>>>;
struct MutableRouterState<R>
where
@@ -70,10 +71,7 @@ impl<R> GenericRouterContext<R>
where
R: Routable,
{
pub(crate) fn new(
cfg: RouterConfiguration<R>,
mark_dirty: Arc<dyn Fn(ScopeId) + Sync + Send>,
) -> Self
pub(crate) fn new(cfg: RouterConfig<R>, mark_dirty: Arc<dyn Fn(ScopeId) + Sync + Send>) -> Self
where
R: Clone,
{
+5 -7
View File
@@ -33,17 +33,15 @@ where
/// OtherPage {},
/// }
///
/// let mut history = MemoryHistory::<Route>::with_initial_path("/").unwrap();
/// let mut history = MemoryHistory::<Route>::with_initial_path(Route::Index {}).unwrap();
/// assert_eq!(history.current_route(), Route::Index {});
/// assert_eq!(history.can_go_back(), false);
/// ```
pub fn with_initial_path(path: impl AsRef<str>) -> Result<Self, <R as FromStr>::Err> {
let path = path.as_ref();
Ok(Self {
current: R::from_str(path)?,
pub fn with_initial_path(path: R) -> Self {
Self {
current: path,
..Default::default()
})
}
}
}
+1 -1
View File
@@ -56,7 +56,7 @@ pub mod prelude {
pub use crate::hooks::*;
pub use crate::navigation::*;
pub use crate::routable::*;
pub use crate::router_cfg::RouterConfiguration;
pub use crate::router_cfg::RouterConfig;
pub use dioxus_router_macro::Routable;
#[doc(hidden)]
+4 -4
View File
@@ -23,15 +23,15 @@ use crate::prelude::*;
/// #[route("/")]
/// Index {},
/// }
/// let cfg = RouterConfiguration::default().history(WebHistory<Route>::default());
/// let cfg = RouterConfig::default().history(WebHistory<Route>::default());
/// ```
pub struct RouterConfiguration<R: Routable> {
pub struct RouterConfig<R: Routable> {
pub(crate) failure_external_navigation: fn(Scope) -> Element,
pub(crate) history: Box<dyn HistoryProvider<R>>,
pub(crate) on_update: Option<RoutingCallback<R>>,
}
impl<R: Routable + Clone> Default for RouterConfiguration<R>
impl<R: Routable + Clone> Default for RouterConfig<R>
where
<R as std::str::FromStr>::Err: std::fmt::Display,
{
@@ -50,7 +50,7 @@ where
}
}
impl<R: Routable> RouterConfiguration<R> {
impl<R: Routable> RouterConfig<R> {
/// A function to be called whenever the routing is updated.
///
/// The callback is invoked after the routing is updated, but before components and hooks are