From fbc6be922d92365007ec76f3d94449f28560debf Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Wed, 12 Jun 2024 21:35:42 -0400 Subject: [PATCH] reorganize Outlet export --- examples/router/src/lib.rs | 4 ++-- router/src/components.rs | 14 ++++++++++++-- router/src/hooks.rs | 3 ++- router/src/lib.rs | 6 ++---- router/src/nested_router.rs | 4 ---- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/examples/router/src/lib.rs b/examples/router/src/lib.rs index 0b77e5302..5b0a9b920 100644 --- a/examples/router/src/lib.rs +++ b/examples/router/src/lib.rs @@ -3,10 +3,10 @@ use crate::api::*; use leptos::either::Either; use leptos::prelude::*; use leptos_router::{ - components::{ParentRoute, Redirect, Route, Router, Routes, A}, + components::{Outlet, ParentRoute, Redirect, Route, Router, Routes, A}, hooks::{use_navigate, use_params, use_query_map}, params::Params, - MatchNestedRoutes, Outlet, ParamSegment, StaticSegment, + MatchNestedRoutes, ParamSegment, StaticSegment, }; use tracing::info; diff --git a/router/src/components.rs b/router/src/components.rs index 69396283e..8238b0453 100644 --- a/router/src/components.rs +++ b/router/src/components.rs @@ -1,15 +1,17 @@ pub use super::link::*; #[cfg(feature = "ssr")] use crate::location::RequestUrl; +pub use crate::nested_router::Outlet; use crate::{ + flat_router::FlatRoutesView, hooks::use_navigate, location::{ BrowserUrl, Location, LocationChange, LocationProvider, State, Url, }, navigate::NavigateOptions, + nested_router::NestedRoutesView, resolve_path::resolve_path, - ChooseView, FlatRoutesView, MatchNestedRoutes, NestedRoute, - NestedRoutesView, Routes, SsrMode, + ChooseView, MatchNestedRoutes, NestedRoute, Routes, SsrMode, }; use leptos::prelude::*; use reactive_graph::{ @@ -344,6 +346,14 @@ where } // redirect on the client else { + if cfg!(feature = "ssr") { + #[cfg(feature = "tracing")] + tracing::warn!( + "Calling without a ServerRedirectFunction \ + provided, in SSR mode." + ); + return; + } let navigate = use_navigate(); navigate(&path, options.unwrap_or_default()); } diff --git a/router/src/hooks.rs b/router/src/hooks.rs index 09a921494..29045d8bd 100644 --- a/router/src/hooks.rs +++ b/router/src/hooks.rs @@ -2,8 +2,8 @@ use crate::{ components::RouterContext, location::{Location, Url}, navigate::NavigateOptions, + nested_router::RouteContext, params::{Params, ParamsError, ParamsMap}, - RouteContext, }; use reactive_graph::{ computed::{ArcMemo, Memo}, @@ -192,6 +192,7 @@ pub(crate) fn use_resolved_path( ) -> ArcMemo> { let router = use_context::() .expect("called use_resolved_path outside a "); + // TODO make this work with flat routes too? let matched = use_context::>().map(|route| route.matched); ArcMemo::new(move |_| { let path = path(); diff --git a/router/src/lib.rs b/router/src/lib.rs index 8bea41a85..7b34a6d49 100644 --- a/router/src/lib.rs +++ b/router/src/lib.rs @@ -3,7 +3,7 @@ #![cfg_attr(feature = "nightly", feature(negative_impls))] pub mod components; -mod flat_router; +pub mod flat_router; mod generate_route_list; pub mod hooks; mod link; @@ -11,18 +11,16 @@ pub mod location; mod matching; mod method; mod navigate; -mod nested_router; +pub mod nested_router; pub mod params; //mod router; mod ssr_mode; mod static_route; -pub use flat_router::*; pub use generate_route_list::*; pub use matching::*; pub use method::*; pub use navigate::*; -pub use nested_router::*; //pub use router::*; pub use ssr_mode::*; pub use static_route::*; diff --git a/router/src/nested_router.rs b/router/src/nested_router.rs index c640b248d..6203cbdb2 100644 --- a/router/src/nested_router.rs +++ b/router/src/nested_router.rs @@ -42,10 +42,6 @@ use tachys::{ }, }; -pub struct Outlet { - rndr: PhantomData, -} - pub(crate) struct NestedRoutesView { pub location: Option, pub routes: Routes,