Merge pull request #169 from DioxusLabs/jk/router-userouter

feat: enable use_router
This commit is contained in:
Jonathan Kelley authored and GitHub committed 2022-01-29 10:15:00 -05:00
commit 3509602c0b
1 file changed
+8
+8
View File
@@ -104,3 +104,11 @@ impl Drop for UseRouteListener {
self.router.router.unsubscribe_onchange(self.scope)
}
}
/// This hook provides access to the `RouterService` for the app.
pub fn use_router(cx: &ScopeState) -> &RouterService {
cx.use_hook(|_| {
cx.consume_context::<RouterService>()
.expect("Cannot call use_route outside the scope of a Router component")
})
}