diff --git a/packages/router/src/hooks/use_route.rs b/packages/router/src/hooks/use_route.rs index 3b609f5e2..31a157a8f 100644 --- a/packages/router/src/hooks/use_route.rs +++ b/packages/router/src/hooks/use_route.rs @@ -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::() + .expect("Cannot call use_route outside the scope of a Router component") + }) +}