fix use_router_internal
This commit is contained in:
1 parent
5ca0c9cbf8
commit
adf67b4384
1 file changed
+10
-13
@@ -11,22 +11,19 @@ use crate::prelude::*;
|
|||||||
/// - [`None`], when the current component isn't a descendant of a [`Link`] component.
|
/// - [`None`], when the current component isn't a descendant of a [`Link`] component.
|
||||||
/// - Otherwise [`Some`].
|
/// - Otherwise [`Some`].
|
||||||
pub(crate) fn use_router_internal() -> Option<RouterContext> {
|
pub(crate) fn use_router_internal() -> Option<RouterContext> {
|
||||||
let router = use_hook(|| {
|
let router = use_hook(consume_context::<RouterContext>);
|
||||||
let router = consume_context::<RouterContext>();
|
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");
|
let id = current_scope_id().expect("use_router_internal called outside of a component");
|
||||||
router.subscribe(id);
|
router.subscribe(id);
|
||||||
|
|
||||||
Some(router)
|
Some(router)
|
||||||
});
|
})
|
||||||
|
|
||||||
use_on_destroy(|| {
|
|
||||||
let router = consume_context::<RouterContext>();
|
|
||||||
|
|
||||||
let id = current_scope_id().expect("use_router_internal called outside of a component");
|
|
||||||
|
|
||||||
router.unsubscribe(id);
|
|
||||||
});
|
|
||||||
|
|
||||||
router
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user