From e26393a42c3e5ae860abc47a85f3ce137a302ba4 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Thu, 17 Nov 2022 20:30:18 -0500 Subject: [PATCH] Fix router issues --- router/src/components/routes.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/router/src/components/routes.rs b/router/src/components/routes.rs index 55de45ee4..abe919000 100644 --- a/router/src/components/routes.rs +++ b/router/src/components/routes.rs @@ -40,7 +40,7 @@ pub fn Routes(cx: Scope, props: RoutesProps) -> impl IntoChild { }); // Rebuild the list of nested routes conservatively, and show the root route here - let mut disposers = Vec::::new(); + let disposers = RefCell::new(Vec::::new()); // iterate over the new matches, reusing old routes when they are the same // and replacing them with new routes when they differ @@ -54,7 +54,7 @@ pub fn Routes(cx: Scope, props: RoutesProps) -> impl IntoChild { root_equal.set(true); next.borrow_mut().clear(); - let next_matches = matches(); + let next_matches = matches.get(); let prev_matches = prev.as_ref().map(|p| &p.matches); let prev_routes = prev.as_ref().map(|p| &p.routes); @@ -103,7 +103,7 @@ pub fn Routes(cx: Scope, props: RoutesProps) -> impl IntoChild { } }, move || { - matches().get(i).cloned() + matches.with(|m| m.get(i).cloned()) } ); @@ -117,11 +117,12 @@ pub fn Routes(cx: Scope, props: RoutesProps) -> impl IntoChild { } }); - if disposers.len() > i + 1 { + if disposers.borrow().len() > i + 1 { + let mut disposers = disposers.borrow_mut(); let old_route_disposer = std::mem::replace(&mut disposers[i], disposer); old_route_disposer.dispose(); } else { - disposers.push(disposer); + disposers.borrow_mut().push(disposer); } } }