From 5f37dcc2ac34330e7f9661db033b4b03c8378ebf Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Thu, 13 Jul 2023 19:56:30 -0700 Subject: [PATCH] fix layouts in child routes --- packages/router/src/components/router.rs | 10 ++++++++++ packages/router/src/contexts/outlet.rs | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/router/src/components/router.rs b/packages/router/src/components/router.rs index e3434721f..7c82cf19b 100644 --- a/packages/router/src/components/router.rs +++ b/packages/router/src/components/router.rs @@ -119,6 +119,8 @@ pub fn GenericRouter(cx: Scope>) -> E where ::Err: std::fmt::Display, { + use crate::prelude::outlet::OutletContext; + use_context_provider(cx, || { GenericRouterContext::new( (cx.props @@ -129,6 +131,10 @@ where cx.schedule_update_any(), ) }); + use_context_provider(cx, || OutletContext:: { + current_level: 0, + _marker: std::marker::PhantomData, + }); render! { GenericOutlet:: {} @@ -152,6 +158,10 @@ where cx.schedule_update_any(), ) }); + use_context_provider(cx, || OutletContext:: { + current_level: 0, + _marker: std::marker::PhantomData, + }); render! { GenericOutlet:: {} diff --git a/packages/router/src/contexts/outlet.rs b/packages/router/src/contexts/outlet.rs index b05db4c9c..6284e25f8 100644 --- a/packages/router/src/contexts/outlet.rs +++ b/packages/router/src/contexts/outlet.rs @@ -4,7 +4,7 @@ use crate::{routable::Routable, utils::use_router_internal::use_router_internal} pub(crate) struct OutletContext { pub current_level: usize, - _marker: std::marker::PhantomData, + pub _marker: std::marker::PhantomData, } impl Clone for OutletContext { @@ -19,7 +19,7 @@ impl Clone for OutletContext { pub(crate) fn use_outlet_context(cx: &ScopeState) -> &OutletContext { let outlet_context = cx.use_hook(|| { cx.consume_context().unwrap_or(OutletContext:: { - current_level: 0, + current_level: 1, _marker: std::marker::PhantomData, }) });