Fix the router and stub out a number of crates to get compiling

This commit is contained in:
Jonathan Kelley committed 2024-01-13 20:51:37 -08:00
1 parent 4c6e515da4
commit fae0b08e61
226 files changed
+1057 -1482

No files matched your search

+7 -8
View File
@@ -1,4 +1,4 @@
use dioxus::prelude::ScopeState;
use dioxus::prelude::{consume_context, use_hook};
use crate::prelude::{Navigator, RouterContext};
@@ -18,14 +18,14 @@ use crate::prelude::{Navigator, RouterContext};
/// }
///
/// #[component]
/// fn App(cx: Scope) -> Element {
/// fn App() -> Element {
/// render! {
/// Router::<Route> {}
/// }
/// }
///
/// #[component]
/// fn Index(cx: Scope) -> Element {
/// fn Index() -> Element {
/// let navigator = use_navigator(&cx);
///
/// render! {
@@ -37,7 +37,7 @@ use crate::prelude::{Navigator, RouterContext};
/// }
///
/// #[component]
/// fn Dynamic(cx: Scope, id: usize) -> Element {
/// fn Dynamic(id: usize) -> Element {
/// render! {
/// p {
/// "Current ID: {id}"
@@ -49,10 +49,9 @@ use crate::prelude::{Navigator, RouterContext};
/// # let _ = vdom.rebuild();
/// ```
#[must_use]
pub fn use_navigator(cx: &ScopeState) -> &Navigator {
&*cx.use_hook(|| {
let router = cx
.consume_context::<RouterContext>()
pub fn use_navigator() -> Navigator {
use_hook(|| {
let router = consume_context::<RouterContext>()
.expect("Must be called in a descendant of a Router component");
Navigator(router)
+4 -6
View File
@@ -1,5 +1,3 @@
use dioxus::prelude::ScopeState;
use crate::prelude::*;
use crate::utils::use_router_internal::use_router_internal;
@@ -26,7 +24,7 @@ use crate::utils::use_router_internal::use_router_internal;
/// }
///
/// #[component]
/// fn App(cx: Scope) -> Element {
/// fn App() -> Element {
/// render! {
/// h1 { "App" }
/// Router::<Route> {}
@@ -34,7 +32,7 @@ use crate::utils::use_router_internal::use_router_internal;
/// }
///
/// #[component]
/// fn Index(cx: Scope) -> Element {
/// fn Index() -> Element {
/// let path: Route = use_route(&cx).unwrap();
/// render! {
/// h2 { "Current Path" }
@@ -47,8 +45,8 @@ use crate::utils::use_router_internal::use_router_internal;
/// # assert_eq!(dioxus_ssr::render(&vdom), "<h1>App</h1><h2>Current Path</h2><p>/</p>")
/// ```
#[must_use]
pub fn use_route<R: Routable + Clone>(cx: &ScopeState) -> Option<R> {
match use_router_internal(cx) {
pub fn use_route<R: Routable + Clone>() -> Option<R> {
match use_router_internal() {
Some(r) => Some(r.current()),
None => {
#[cfg(debug_assertions)]
+2 -6
View File
@@ -1,14 +1,10 @@
use dioxus::prelude::ScopeState;
use crate::{prelude::RouterContext, utils::use_router_internal::use_router_internal};
#[deprecated = "prefer the `router()` function or `use_route` functions"]
#[must_use]
/// A hook that provides access to information about the router.
pub fn use_router(cx: &ScopeState) -> &RouterContext {
use_router_internal(cx)
.as_ref()
.expect("use_route must have access to a router")
pub fn use_router() -> RouterContext {
use_router_internal().expect("use_route must have access to a router")
}
/// Aquire the router without subscribing to updates.