fix: Update dioxus-router docs
This commit is contained in:
3 files changed
+6
-10
No files matched your search
@@ -2,7 +2,7 @@ use dioxus_lib::prelude::{try_consume_context, use_hook};
|
|||||||
|
|
||||||
use crate::prelude::{Navigator, RouterContext};
|
use crate::prelude::{Navigator, 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
|
/// A hook that provides access to the navigator to change the router history.
|
||||||
///
|
///
|
||||||
/// > The Routable macro will define a version of this hook with an explicit type.
|
/// > The Routable macro will define a version of this hook with an explicit type.
|
||||||
///
|
///
|
||||||
@@ -26,7 +26,7 @@ use crate::prelude::{Navigator, RouterContext};
|
|||||||
///
|
///
|
||||||
/// #[component]
|
/// #[component]
|
||||||
/// fn Index() -> Element {
|
/// fn Index() -> Element {
|
||||||
/// let navigator = use_navigator(&cx);
|
/// let navigator = use_navigator();
|
||||||
///
|
///
|
||||||
/// rsx! {
|
/// rsx! {
|
||||||
/// button {
|
/// button {
|
||||||
|
|||||||
@@ -5,12 +5,8 @@ use crate::utils::use_router_internal::use_router_internal;
|
|||||||
///
|
///
|
||||||
/// > The Routable macro will define a version of this hook with an explicit type.
|
/// > The Routable macro will define a version of this hook with an explicit type.
|
||||||
///
|
///
|
||||||
/// # Return values
|
|
||||||
/// - None, when not called inside a [`Link`] component.
|
|
||||||
/// - Otherwise the current route.
|
|
||||||
///
|
|
||||||
/// # Panic
|
/// # Panic
|
||||||
/// - When the calling component is not nested within a [`Link`] component during a debug build.
|
/// - When the calling component is not nested within a [`Router`] component.
|
||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```rust
|
/// ```rust
|
||||||
@@ -49,7 +45,7 @@ pub fn use_route<R: Routable + Clone>() -> R {
|
|||||||
match use_router_internal() {
|
match use_router_internal() {
|
||||||
Some(r) => r.current(),
|
Some(r) => r.current(),
|
||||||
None => {
|
None => {
|
||||||
panic!("`use_route` must have access to a parent router")
|
panic!("`use_route` must be called in a descendant of a Router component")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,10 +8,10 @@ use crate::prelude::*;
|
|||||||
/// single component, but not recommended. Multiple subscriptions will be discarded.
|
/// single component, but not recommended. Multiple subscriptions will be discarded.
|
||||||
///
|
///
|
||||||
/// # Return values
|
/// # Return values
|
||||||
/// - [`None`], when the current component isn't a descendant of a [`Link`] component.
|
/// - [`None`], when the current component isn't a descendant of a [`Router`] 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(consume_context::<RouterContext>);
|
let router = try_consume_context::<RouterContext>()?;
|
||||||
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");
|
||||||
use_drop({
|
use_drop({
|
||||||
to_owned![router];
|
to_owned![router];
|
||||||
|
|||||||
Reference in new issue
Block a user