From 146c36cbe761b733612f7134b8d7c5a84c3e2d18 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Tue, 31 Dec 2024 10:33:59 -0500 Subject: [PATCH] fix: correct ownership in redirect route hook (closes #3425) --- router/src/components.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/router/src/components.rs b/router/src/components.rs index 6f7c37b938..54def99e5b 100644 --- a/router/src/components.rs +++ b/router/src/components.rs @@ -82,13 +82,18 @@ where #[cfg(not(feature = "ssr"))] let (location_provider, current_url, redirect_hook) = { + let owner = Owner::current(); let location = BrowserUrl::new().expect("could not access browser navigation"); // TODO options here location.init(base.clone()); provide_context(location.clone()); let current_url = location.as_url().clone(); - let redirect_hook = Box::new(|loc: &str| BrowserUrl::redirect(loc)); + let redirect_hook = Box::new(move |loc: &str| { + if let Some(owner) = &owner { + owner.with(|| BrowserUrl::redirect(loc)); + } + }); (Some(location), current_url, redirect_hook) };