Merge branch 'master' into events-2
This commit is contained in:
commit
dccfba12d8
209 files changed
+6270
-2789
No files matched your search
@@ -55,9 +55,7 @@ fn main() {
|
||||
#[component]
|
||||
fn Root(cx: Scope) -> Element {
|
||||
let history = LiveviewHistory::new(cx);
|
||||
render! { Router::<Route> {
|
||||
config: || RouterConfig::default().history(history),
|
||||
} }
|
||||
render! { Router::<Route> { config: || RouterConfig::default().history(history) } }
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "liveview"))]
|
||||
@@ -84,12 +82,19 @@ fn Route1(cx: Scope, user_id: usize, dynamic: usize, query: String, extra: Strin
|
||||
"Route1{{\n\tuser_id:{user_id},\n\tdynamic:{dynamic},\n\tquery:{query},\n\textra:{extra}\n}}"
|
||||
}
|
||||
Link {
|
||||
to: Route::Route1 { user_id: *user_id, dynamic: *dynamic, query: String::new(), extra: extra.clone() + "." },
|
||||
to: Route::Route1 {
|
||||
user_id: *user_id,
|
||||
dynamic: *dynamic,
|
||||
query: String::new(),
|
||||
extra: extra.clone() + ".",
|
||||
},
|
||||
"Route1 with extra+\".\""
|
||||
}
|
||||
p { "Footer" }
|
||||
Link {
|
||||
to: Route::Route3 { dynamic: String::new() },
|
||||
to: Route::Route3 {
|
||||
dynamic: String::new(),
|
||||
},
|
||||
"Home"
|
||||
}
|
||||
}
|
||||
@@ -98,13 +103,13 @@ fn Route1(cx: Scope, user_id: usize, dynamic: usize, query: String, extra: Strin
|
||||
#[component]
|
||||
fn Route2(cx: Scope, user_id: usize) -> Element {
|
||||
render! {
|
||||
pre {
|
||||
"Route2{{\n\tuser_id:{user_id}\n}}"
|
||||
}
|
||||
pre { "Route2{{\n\tuser_id:{user_id}\n}}" }
|
||||
(0..*user_id).map(|i| rsx!{ p { "{i}" } }),
|
||||
p { "Footer" }
|
||||
Link {
|
||||
to: Route::Route3 { dynamic: String::new() },
|
||||
to: Route::Route3 {
|
||||
dynamic: String::new(),
|
||||
},
|
||||
"Home"
|
||||
}
|
||||
}
|
||||
@@ -112,7 +117,6 @@ fn Route2(cx: Scope, user_id: usize) -> Element {
|
||||
|
||||
#[component]
|
||||
fn Route3(cx: Scope, dynamic: String) -> Element {
|
||||
let navigator = use_navigator(cx);
|
||||
let current_route = use_route(cx)?;
|
||||
let current_route_str = use_ref(cx, String::new);
|
||||
let parsed = Route::from_str(¤t_route_str.read());
|
||||
@@ -122,6 +126,8 @@ fn Route3(cx: Scope, dynamic: String) -> Element {
|
||||
.flat_map(|seg| seg.flatten().into_iter())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let navigator = use_navigator(cx);
|
||||
|
||||
render! {
|
||||
input {
|
||||
oninput: move |evt| {
|
||||
@@ -130,22 +136,25 @@ fn Route3(cx: Scope, dynamic: String) -> Element {
|
||||
value: "{current_route_str.read()}"
|
||||
}
|
||||
"dynamic: {dynamic}"
|
||||
Link {
|
||||
to: Route::Route2 { user_id: 8888 },
|
||||
"hello world link"
|
||||
}
|
||||
Link { to: Route::Route2 { user_id: 8888 }, "hello world link" }
|
||||
button {
|
||||
disabled: !navigator.can_go_back(),
|
||||
onclick: move |_| { navigator.go_back(); },
|
||||
onclick: move |_| {
|
||||
navigator.go_back();
|
||||
},
|
||||
"go back"
|
||||
}
|
||||
button {
|
||||
disabled: !navigator.can_go_forward(),
|
||||
onclick: move |_| { navigator.go_forward(); },
|
||||
onclick: move |_| {
|
||||
navigator.go_forward();
|
||||
},
|
||||
"go forward"
|
||||
}
|
||||
button {
|
||||
onclick: move |_| { navigator.push("https://www.google.com"); },
|
||||
onclick: move |_| {
|
||||
navigator.push("https://www.google.com");
|
||||
},
|
||||
"google link"
|
||||
}
|
||||
p { "Site Map" }
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
use crate::prelude::{ExternalNavigationFailure, IntoRoutable, RouterContext};
|
||||
|
||||
/// Acquire the navigator without subscribing to updates.
|
||||
///
|
||||
/// Can be called anywhere in the application provided a Router has been initialized.
|
||||
///
|
||||
/// ## Panics
|
||||
///
|
||||
/// Panics if there is no router present.
|
||||
pub fn navigator() -> Navigator {
|
||||
Navigator(
|
||||
dioxus::core::prelude::consume_context::<RouterContext>()
|
||||
.expect("A router must be present to use navigator"),
|
||||
)
|
||||
}
|
||||
|
||||
/// A view into the navigation state of a router.
|
||||
#[derive(Clone)]
|
||||
pub struct Navigator(pub(crate) RouterContext);
|
||||
|
||||
@@ -49,6 +49,7 @@ use crate::prelude::{Navigator, RouterContext};
|
||||
/// # let _ = vdom.rebuild();
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[deprecated = "Prefer acquiring the router directly with `dioxus_router::router()`"]
|
||||
pub fn use_navigator(cx: &ScopeState) -> &Navigator {
|
||||
&*cx.use_hook(|| {
|
||||
let router = cx
|
||||
|
||||
@@ -2,7 +2,7 @@ use dioxus::prelude::ScopeState;
|
||||
|
||||
use crate::{prelude::RouterContext, utils::use_router_internal::use_router_internal};
|
||||
|
||||
#[deprecated = "prefer the use_navigator or use_route functions"]
|
||||
#[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 {
|
||||
@@ -10,3 +10,8 @@ pub fn use_router(cx: &ScopeState) -> &RouterContext {
|
||||
.as_ref()
|
||||
.expect("use_route must have access to a router")
|
||||
}
|
||||
|
||||
/// Aquire the router without subscribing to updates.
|
||||
pub fn router() -> RouterContext {
|
||||
dioxus::core::prelude::consume_context().unwrap()
|
||||
}
|
||||
@@ -53,6 +53,8 @@ pub mod hooks {
|
||||
pub use use_navigator::*;
|
||||
}
|
||||
|
||||
pub use hooks::router;
|
||||
|
||||
/// A collection of useful items most applications might need.
|
||||
pub mod prelude {
|
||||
pub use crate::components::*;
|
||||
|
||||
Reference in new issue
Block a user