it almost lives?
This commit is contained in:
1 parent
d637ef187c
commit
5f0dd3af3e
43 files changed
+506
-244
No files matched your search
@@ -1,9 +1,6 @@
|
||||
use dioxus::prelude::ScopeState;
|
||||
|
||||
use crate::{
|
||||
prelude::{GenericNavigator, GenericRouterContext},
|
||||
routable::Routable,
|
||||
};
|
||||
use crate::prelude::{GenericNavigator, RouterContext};
|
||||
|
||||
/// A hook that provides access to the navigator to change the router history. Unlike [`use_router`], this hook will not cause a rerender when the current route changes
|
||||
///
|
||||
@@ -22,7 +19,7 @@ use crate::{
|
||||
///
|
||||
/// fn App(cx: Scope) -> Element {
|
||||
/// render! {
|
||||
/// Router {}
|
||||
/// Router::<Route> {}
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
@@ -50,10 +47,10 @@ use crate::{
|
||||
/// # let mut vdom = VirtualDom::new(App);
|
||||
/// # let _ = vdom.rebuild();
|
||||
/// ```
|
||||
pub fn use_generic_navigator<R: Routable + Clone>(cx: &ScopeState) -> &GenericNavigator<R> {
|
||||
pub fn use_navigator(cx: &ScopeState) -> &GenericNavigator {
|
||||
&*cx.use_hook(|| {
|
||||
let router = cx
|
||||
.consume_context::<GenericRouterContext<R>>()
|
||||
.consume_context::<RouterContext>()
|
||||
.expect("Must be called in a descendant of a Router component");
|
||||
|
||||
GenericNavigator(router)
|
||||
|
||||
@@ -8,11 +8,11 @@ use crate::utils::use_router_internal::use_router_internal;
|
||||
/// > The Routable macro will define a version of this hook with an explicit type.
|
||||
///
|
||||
/// # Return values
|
||||
/// - None, when not called inside a [`GenericRouter`] component.
|
||||
/// - None, when not called inside a [`Link`] component.
|
||||
/// - Otherwise the current route.
|
||||
///
|
||||
/// # Panic
|
||||
/// - When the calling component is not nested within a [`GenericRouter`] component durring a debug build.
|
||||
/// - When the calling component is not nested within a [`Link`] component durring a debug build.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
@@ -28,7 +28,7 @@ use crate::utils::use_router_internal::use_router_internal;
|
||||
/// fn App(cx: Scope) -> Element {
|
||||
/// render! {
|
||||
/// h1 { "App" }
|
||||
/// Router {}
|
||||
/// Router::<Route> {}
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
@@ -45,7 +45,7 @@ use crate::utils::use_router_internal::use_router_internal;
|
||||
/// # let _ = vdom.rebuild();
|
||||
/// # assert_eq!(dioxus_ssr::render(&vdom), "<h1>App</h1><h2>Current Path</h2><p>/</p>")
|
||||
/// ```
|
||||
pub fn use_generic_route<R: Routable + Clone>(cx: &ScopeState) -> Option<R> {
|
||||
pub fn use_route<R: Routable + Clone>(cx: &ScopeState) -> Option<R> {
|
||||
match use_router_internal(cx) {
|
||||
Some(r) => Some(r.current()),
|
||||
None => {
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
use dioxus::prelude::ScopeState;
|
||||
|
||||
use crate::{
|
||||
prelude::GenericRouterContext, routable::Routable,
|
||||
utils::use_router_internal::use_router_internal,
|
||||
};
|
||||
use crate::{prelude::RouterContext, utils::use_router_internal::use_router_internal};
|
||||
|
||||
/// A hook that provides access to information about the router.
|
||||
pub fn use_generic_router<R: Routable + Clone>(cx: &ScopeState) -> &GenericRouterContext<R> {
|
||||
pub fn use_router(cx: &ScopeState) -> &RouterContext {
|
||||
use_router_internal(cx)
|
||||
.as_ref()
|
||||
.expect("use_route must have access to a router")
|
||||
|
||||
Reference in new issue
Block a user