create non generic wrappers for each route

This commit is contained in:
Evan Almloff committed 2023-05-23 19:31:30 -05:00
1 parent 3678fa1d3f
commit d3b21879fb
9 files changed
+58 -32

No files matched your search

@@ -1,4 +1,6 @@
use crate::{components::Link, hooks::use_route, navigation::NavigationTarget, routable::Routable};
use crate::{
components::GenericLink, hooks::use_route, navigation::NavigationTarget, routable::Routable,
};
use dioxus::prelude::*;
#[allow(non_snake_case)]
@@ -35,7 +37,7 @@ pub fn FailureNamedNavigation<R: Routable + Clone>(cx: Scope) -> Element {
"We are sorry for the inconvenience. The link below may help to fix the problem, but "
"there is no guarantee."
}
Link::<R> {
GenericLink::<R> {
target: NavigationTarget::External("https://google.com".into()),
"Click here to try to fix the failure."
}
@@ -55,7 +57,7 @@ pub fn FailureRedirectionLimit<R: Routable + Clone>(cx: Scope) -> Element {
"We are sorry for the inconvenience. The link below may help to fix the problem, but "
"there is no guarantee."
}
Link::<R> {
GenericLink::<R> {
target: NavigationTarget::External("https://google.com".into()),
"Click here to try to fix the failure."
}
+4 -4
View File
@@ -9,7 +9,7 @@ use crate::utils::use_router_internal::use_router_internal;
/// The properties for a [`Link`].
#[derive(Props)]
pub struct LinkProps<'a, R: Routable> {
pub struct GenericLinkProps<'a, R: Routable> {
/// A class to apply to the generate HTML anchor tag if the `target` route is active.
pub active_class: Option<&'a str>,
/// The children to render within the generated HTML anchor tag.
@@ -45,7 +45,7 @@ pub struct LinkProps<'a, R: Routable> {
pub target: NavigationTarget<R>,
}
impl<R: Routable> Debug for LinkProps<'_, R> {
impl<R: Routable> Debug for GenericLinkProps<'_, R> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("LinkProps")
.field("active_class", &self.active_class)
@@ -125,8 +125,8 @@ impl<R: Routable> Debug for LinkProps<'_, R> {
/// # );
/// ```
#[allow(non_snake_case)]
pub fn Link<'a, R: Routable + Clone>(cx: Scope<'a, LinkProps<'a, R>>) -> Element {
let LinkProps {
pub fn GenericLink<'a, R: Routable + Clone>(cx: Scope<'a, GenericLinkProps<'a, R>>) -> Element {
let GenericLinkProps {
active_class,
children,
class,
+1 -1
View File
@@ -44,6 +44,6 @@ use dioxus::prelude::*;
/// # let _ = vdom.rebuild();
/// # assert_eq!(dioxus_ssr::render(&vdom), "<h1>App</h1><p>Content</p>");
/// ```
pub fn Outlet<R: Routable + Clone>(cx: Scope) -> Element {
pub fn GenericOutlet<R: Routable + Clone>(cx: Scope) -> Element {
OutletContext::render::<R>(cx)
}
+7 -7
View File
@@ -3,7 +3,7 @@ use log::error;
use std::{cell::RefCell, str::FromStr};
use crate::{
prelude::{Outlet, RouterContext},
prelude::{GenericOutlet, GenericRouterContext},
routable::Routable,
router_cfg::RouterConfiguration,
};
@@ -34,7 +34,7 @@ impl<R: Routable> From<RouterConfiguration<R>> for RouterCfg<R> {
/// The props for [`Router`].
#[derive(Props)]
pub struct RouterProps<R: Routable>
pub struct GenericRouterProps<R: Routable>
where
<R as FromStr>::Err: std::fmt::Display,
{
@@ -44,7 +44,7 @@ where
config: RouterCfg<R>,
}
impl<R: Routable> PartialEq for RouterProps<R>
impl<R: Routable> PartialEq for GenericRouterProps<R>
where
<R as FromStr>::Err: std::fmt::Display,
{
@@ -55,19 +55,19 @@ where
}
/// A component that renders the current route.
pub fn Router<R: Routable + Clone>(cx: Scope<RouterProps<R>>) -> Element
pub fn GenericRouter<R: Routable + Clone>(cx: Scope<GenericRouterProps<R>>) -> Element
where
<R as FromStr>::Err: std::fmt::Display,
{
use_context_provider(cx, || {
#[allow(unreachable_code, unused_variables)]
if let Some(outer) = cx.consume_context::<RouterContext<R>>() {
if let Some(outer) = cx.consume_context::<GenericRouterContext<R>>() {
let msg = "Router components should not be nested within each other";
error!("{msg}, inner will be inactive and transparent");
#[cfg(debug_assertions)]
panic!("{}", msg);
}
let router = RouterContext::new(
let router = GenericRouterContext::new(
cx.props.config.config.take().unwrap_or_default(),
cx.schedule_update_any(),
);
@@ -82,6 +82,6 @@ where
});
render! {
Outlet::<R> {}
GenericOutlet::<R> {}
}
}