Przeglądaj źródła

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

feat: enable use_router
Jonathan Kelley 3 lat temu
rodzic
commit
3509602c0b
1 zmienionych plików z 8 dodań i 0 usunięć
  1. 8 0
      packages/router/src/hooks/use_route.rs

+ 8 - 0
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::<RouterService>()
+            .expect("Cannot call use_route outside the scope of a Router component")
+    })
+}