diff --git a/examples/router.rs b/examples/router.rs index b994d656b..72844dc11 100644 --- a/examples/router.rs +++ b/examples/router.rs @@ -49,13 +49,11 @@ fn NavBar() -> Element { #[component] fn Home() -> Element { - println!("Home"); rsx! { h1 { "Welcome to the Dioxus Blog!" } } } #[component] fn Blog() -> Element { - println!("Blog"); rsx! { h1 { "Blog" } Outlet:: {} diff --git a/packages/router/src/utils/use_router_internal.rs b/packages/router/src/utils/use_router_internal.rs index 55997c304..7d00f821f 100644 --- a/packages/router/src/utils/use_router_internal.rs +++ b/packages/router/src/utils/use_router_internal.rs @@ -12,16 +12,14 @@ use crate::prelude::*; /// - Otherwise [`Some`]. pub(crate) fn use_router_internal() -> Option { let router = use_hook(consume_context::); + let id = current_scope_id().expect("use_router_internal called outside of a component"); use_on_destroy({ to_owned![router]; move || { - let id = current_scope_id().expect("use_router_internal called outside of a component"); - router.unsubscribe(id); } }); use_hook(move || { - let id = current_scope_id().expect("use_router_internal called outside of a component"); router.subscribe(id); Some(router)