Browse Source

fix layouts in child routes

Evan Almloff 1 year ago
parent
commit
5f37dcc2ac
2 changed files with 12 additions and 2 deletions
  1. 10 0
      packages/router/src/components/router.rs
  2. 2 2
      packages/router/src/contexts/outlet.rs

+ 10 - 0
packages/router/src/components/router.rs

@@ -119,6 +119,8 @@ pub fn GenericRouter<R: Routable + Clone>(cx: Scope<GenericRouterProps<R>>) -> E
 where
     <R as FromStr>::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::<R> {
+        current_level: 0,
+        _marker: std::marker::PhantomData,
+    });
 
     render! {
         GenericOutlet::<R> {}
@@ -152,6 +158,10 @@ where
             cx.schedule_update_any(),
         )
     });
+    use_context_provider(cx, || OutletContext::<R> {
+        current_level: 0,
+        _marker: std::marker::PhantomData,
+    });
 
     render! {
         GenericOutlet::<R> {}

+ 2 - 2
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<R> {
     pub current_level: usize,
-    _marker: std::marker::PhantomData<R>,
+    pub _marker: std::marker::PhantomData<R>,
 }
 
 impl<R> Clone for OutletContext<R> {
@@ -19,7 +19,7 @@ impl<R> Clone for OutletContext<R> {
 pub(crate) fn use_outlet_context<R: 'static>(cx: &ScopeState) -> &OutletContext<R> {
     let outlet_context = cx.use_hook(|| {
         cx.consume_context().unwrap_or(OutletContext::<R> {
-            current_level: 0,
+            current_level: 1,
             _marker: std::marker::PhantomData,
         })
     });