fix: tests pass

This commit is contained in:
Jonathan Kelley committed 2022-03-04 13:16:37 -05:00
1 parent 06d4a5640b
commit c7627f0b93
10 files changed
+33 -18

No files matched your search

+3 -2
View File
@@ -31,7 +31,7 @@ fn app(cx: Scope) -> Element {
} }
fn BlogPost(cx: Scope) -> Element { fn BlogPost(cx: Scope) -> Element {
let post = dioxus::router::use_route(&cx).last_segment(); let post = dioxus::router::use_route(&cx).last_segment()?;
cx.render(rsx! { cx.render(rsx! {
div { div {
@@ -47,7 +47,8 @@ struct Query {
} }
fn User(cx: Scope) -> Element { fn User(cx: Scope) -> Element {
let post = dioxus::router::use_route(&cx).last_segment(); let post = dioxus::router::use_route(&cx).last_segment()?;
let query = dioxus::router::use_route(&cx) let query = dioxus::router::use_route(&cx)
.query::<Query>() .query::<Query>()
.unwrap_or(Query { bold: false }); .unwrap_or(Query { bold: false });
+7 -5
View File
@@ -35,12 +35,13 @@ gloo-events = { version = "0.1.1", optional = true }
log = "0.4.14" log = "0.4.14"
thiserror = "1.0.30" thiserror = "1.0.30"
futures-util = "0.3.21" futures-util = "0.3.21"
serde = { version = "1", optional = true }
serde_urlencoded = {version = "0.7.1", optional = true}
[features] [features]
default = ["web"] default = ["query"]
web = ["web-sys", "gloo-events", "js-sys", "wasm-bindgen"] web = ["web-sys", "gloo-events", "js-sys", "wasm-bindgen"]
hash = [] query = ["serde"]
[dev-dependencies] [dev-dependencies]
console_error_panic_hook = "0.1.7" console_error_panic_hook = "0.1.7"
@@ -50,10 +51,11 @@ wasm-logger = "0.2.0"
wasm-bindgen-test = "0.3" wasm-bindgen-test = "0.3"
gloo-utils = "0.1.2" gloo-utils = "0.1.2"
dioxus-ssr = { path = "../ssr"} dioxus-ssr = { path = "../ssr"}
dioxus-router = { path = ".", default-features = false } dioxus-router = { path = ".", default-features = false }
# [target.wasm32-unknown-unknown.dev-dependencies] [target.wasm32-unknown-unknown.dev-dependencies]
# dioxus-router = { path = ".", features = ["web"] } dioxus-router = { path = ".", features = ["web"] }
+1 -1
View File
@@ -51,7 +51,7 @@
Dioxus Router is a first-party Router for all your Dioxus Apps. It provides a React-Router style interface that works anywhere: across the browser, SSR, and natively. Dioxus Router is a first-party Router for all your Dioxus Apps. It provides a React-Router style interface that works anywhere: across the browser, SSR, and natively.
```rust ```rust, ignore
fn app() { fn app() {
cx.render(rsx! { cx.render(rsx! {
Router { Router {
+2 -2
View File
@@ -11,7 +11,7 @@ use dioxus_html as dioxus_elements;
pub struct LinkProps<'a> { pub struct LinkProps<'a> {
/// The route to link to. This can be a relative path, or a full URL. /// The route to link to. This can be a relative path, or a full URL.
/// ///
/// ```rust /// ```rust, ignore
/// // Absolute path /// // Absolute path
/// Link { to: "/home", "Go Home" } /// Link { to: "/home", "Go Home" }
/// ///
@@ -64,7 +64,7 @@ pub struct LinkProps<'a> {
/// ///
/// # Examples /// # Examples
/// ///
/// ```rust /// ```rust, ignore
/// fn Header(cx: Scope) -> Element { /// fn Header(cx: Scope) -> Element {
/// cx.render(rsx!{ /// cx.render(rsx!{
/// Link { to: "/home", "Go Home" } /// Link { to: "/home", "Go Home" }
+2 -2
View File
@@ -9,7 +9,7 @@ use crate::use_router;
pub struct RedirectProps<'a> { pub struct RedirectProps<'a> {
/// The route to link to. This can be a relative path, or a full URL. /// The route to link to. This can be a relative path, or a full URL.
/// ///
/// ```rust /// ```rust, ignore
/// // Absolute path /// // Absolute path
/// Redirect { from: "", to: "/home" } /// Redirect { from: "", to: "/home" }
/// ///
@@ -20,7 +20,7 @@ pub struct RedirectProps<'a> {
/// The route to link from. This can be a relative path, or a full URL. /// The route to link from. This can be a relative path, or a full URL.
/// ///
/// ```rust /// ```rust, ignore
/// // Absolute path /// // Absolute path
/// Redirect { from: "", to: "/home" } /// Redirect { from: "", to: "/home" }
/// ///
+1 -1
View File
@@ -22,7 +22,7 @@ pub struct RouteProps<'a> {
/// ///
/// # Example /// # Example
/// ///
///```rust ///```rust, ignore
/// rsx!( /// rsx!(
/// Router { /// Router {
/// Route { to: "/home", Home {} } /// Route { to: "/home", Home {} }
+10 -1
View File
@@ -48,7 +48,16 @@ impl UseRoute {
/// Get the first query parameter given the parameter name. /// Get the first query parameter given the parameter name.
/// ///
/// If you need to get more than one parameter, use [`query_pairs`] on the [`Url`] instead. /// If you need to get more than one parameter, use [`query_pairs`] on the [`Url`] instead.
pub fn query(&self, param: &str) -> Option<Cow<str>> { #[cfg(feature = "query")]
pub fn query<T: serde::de::DeserializeOwned>(&self) -> Option<T> {
let query = self.url().query()?;
serde_urlencoded::from_str(query.strip_prefix('?').unwrap_or("")).ok()
}
/// Get the first query parameter given the parameter name.
///
/// If you need to get more than one parameter, use [`query_pairs`] on the [`Url`] instead.
pub fn query_param(&self, param: &str) -> Option<Cow<str>> {
self.route self.route
.url .url
.query_pairs() .query_pairs()
+2 -2
View File
@@ -8,7 +8,7 @@ pub struct RouteContext {
/// ///
/// ///
/// It follows this pattern: /// It follows this pattern:
/// ``` /// ```ignore
/// "name/:id" /// "name/:id"
/// ``` /// ```
pub declared_route: String, pub declared_route: String,
@@ -17,7 +17,7 @@ pub struct RouteContext {
/// ///
/// ///
/// It follows this pattern: /// It follows this pattern:
/// ``` /// ```ignore
/// "/level0/level1/:id" /// "/level0/level1/:id"
/// ``` /// ```
pub total_route: String, pub total_route: String,
+3 -1
View File
@@ -29,7 +29,7 @@ use url::Url;
/// ///
/// # Example /// # Example
/// ///
/// ```rust /// ```rust, ignore
/// let router = Router::new(); /// let router = Router::new();
/// router.push_route("/home/custom"); /// router.push_route("/home/custom");
/// cx.provide_context(router); /// cx.provide_context(router);
@@ -280,6 +280,8 @@ mod hash {
serialized_state: None, serialized_state: None,
} }
} }
fn replace(&self, _route: &ParsedRoute) {}
} }
} }
+2 -1
View File
@@ -12,13 +12,14 @@ fn generates_without_error() {
let out = dioxus_ssr::render_vdom(&app); let out = dioxus_ssr::render_vdom(&app);
assert_eq!(out, "<nav>navbar</nav><h1>Home</h1>"); assert_eq!(out, "<nav>navbar</nav>default<!--placeholder-->");
} }
fn app(cx: Scope) -> Element { fn app(cx: Scope) -> Element {
cx.render(rsx! { cx.render(rsx! {
Router { Router {
nav { "navbar" } nav { "navbar" }
Route { to: "/", "default" }
Route { to: "/home", Home {} } Route { to: "/home", Home {} }
} }
}) })