diff --git a/examples/login_form.rs b/examples/login_form.rs index 62c6f982b..cdf05d7c3 100644 --- a/examples/login_form.rs +++ b/examples/login_form.rs @@ -3,20 +3,20 @@ use dioxus::events::*; use dioxus::prelude::*; -use dioxus::router::{Link, Route, Router, RouterService}; +use dioxus::router::{use_router, Link, Route, Router}; fn main() { - dioxus::desktop::launch(APP); + dioxus::desktop::launch(app); } -static APP: Component = |cx| { +fn app(cx: Scope) -> Element { cx.render(rsx! { Router { Route { to: "/", home() } Route { to: "/login", login() } } }) -}; +} fn home(cx: Scope) -> Element { cx.render(rsx! { @@ -26,7 +26,7 @@ fn home(cx: Scope) -> Element { } fn login(cx: Scope) -> Element { - let service = cx.consume_context::()?; + let service = use_router(&cx); let onsubmit = move |evt: FormEvent| { to_owned![service]; @@ -42,10 +42,10 @@ fn login(cx: Scope) -> Element { match resp { // Parse data from here, such as storing a response token - Ok(data) => service.push_route("/"), + Ok(_data) => service.push_route("/"), //Handle any errors from the fetch here - Err(err) => {} + Err(_err) => {} } }); }; @@ -55,13 +55,12 @@ fn login(cx: Scope) -> Element { form { onsubmit: onsubmit, prevent_default: "onsubmit", // Prevent the default behavior of
to post - input { r#type: "text" } + + input { "type": "text" } label { "Username" } br {} - input { r#type: "password" } - label { - "Password" - } + input { "type": "password" } + label { "Password" } br {} button { "Login" } } diff --git a/packages/router/src/hooks/use_route.rs b/packages/router/src/hooks/use_route.rs index 31a157a8f..4de6dff12 100644 --- a/packages/router/src/hooks/use_route.rs +++ b/packages/router/src/hooks/use_route.rs @@ -106,7 +106,7 @@ impl Drop for UseRouteListener { } /// This hook provides access to the `RouterService` for the app. -pub fn use_router(cx: &ScopeState) -> &RouterService { +pub fn use_router(cx: &ScopeState) -> &Rc { cx.use_hook(|_| { cx.consume_context::() .expect("Cannot call use_route outside the scope of a Router component")