create cfg factory
This commit is contained in:
1 parent
037a248ad9
commit
67992f7da9
6 files changed
+90
-72
No files matched your search
@@ -1,10 +1,9 @@
|
||||
#![allow(non_snake_case)]
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_router::prelude::*;
|
||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||
use std::str::FromStr;
|
||||
|
||||
fn prepare<R: Routable + Serialize + DeserializeOwned>() -> String
|
||||
fn prepare<R: Routable>() -> String
|
||||
where
|
||||
<R as FromStr>::Err: std::fmt::Display,
|
||||
{
|
||||
@@ -28,17 +27,14 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
fn App<R: Routable + Serialize + DeserializeOwned>(cx: Scope<AppProps<R>>) -> Element
|
||||
fn App<R: Routable>(cx: Scope<AppProps<R>>) -> Element
|
||||
where
|
||||
<R as FromStr>::Err: std::fmt::Display,
|
||||
{
|
||||
render! {
|
||||
h1 { "App" }
|
||||
GenericRouter::<R> {
|
||||
config: RouterConfiguration {
|
||||
history: Box::<MemoryHistory::<R>>::default(),
|
||||
..Default::default()
|
||||
}
|
||||
config: || RouterConfiguration::default().history(MemoryHistory::default())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,7 +42,7 @@ where
|
||||
|
||||
#[test]
|
||||
fn href_internal() {
|
||||
#[derive(Routable, Clone, Serialize, Deserialize)]
|
||||
#[derive(Routable, Clone)]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
Root {},
|
||||
@@ -84,7 +80,7 @@ fn href_internal() {
|
||||
|
||||
#[test]
|
||||
fn href_external() {
|
||||
#[derive(Routable, Clone, Serialize, Deserialize)]
|
||||
#[derive(Routable, Clone)]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
Root {},
|
||||
@@ -122,7 +118,7 @@ fn href_external() {
|
||||
|
||||
#[test]
|
||||
fn with_class() {
|
||||
#[derive(Routable, Clone, Serialize, Deserialize)]
|
||||
#[derive(Routable, Clone)]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
Root {},
|
||||
@@ -161,7 +157,7 @@ fn with_class() {
|
||||
|
||||
#[test]
|
||||
fn with_active_class_active() {
|
||||
#[derive(Routable, Clone, Serialize, Deserialize)]
|
||||
#[derive(Routable, Clone)]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
Root {},
|
||||
@@ -194,7 +190,7 @@ fn with_active_class_active() {
|
||||
|
||||
#[test]
|
||||
fn with_active_class_inactive() {
|
||||
#[derive(Routable, Clone, Serialize, Deserialize)]
|
||||
#[derive(Routable, Clone)]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
Root {},
|
||||
@@ -234,7 +230,7 @@ fn with_active_class_inactive() {
|
||||
|
||||
#[test]
|
||||
fn with_id() {
|
||||
#[derive(Routable, Clone, Serialize, Deserialize)]
|
||||
#[derive(Routable, Clone)]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
Root {},
|
||||
@@ -273,7 +269,7 @@ fn with_id() {
|
||||
|
||||
#[test]
|
||||
fn with_new_tab() {
|
||||
#[derive(Routable, Clone, Serialize, Deserialize)]
|
||||
#[derive(Routable, Clone)]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
Root {},
|
||||
@@ -312,7 +308,7 @@ fn with_new_tab() {
|
||||
|
||||
#[test]
|
||||
fn with_new_tab_external() {
|
||||
#[derive(Routable, Clone, Serialize, Deserialize)]
|
||||
#[derive(Routable, Clone)]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
Root {},
|
||||
@@ -344,7 +340,7 @@ fn with_new_tab_external() {
|
||||
|
||||
#[test]
|
||||
fn with_rel() {
|
||||
#[derive(Routable, Clone, Serialize, Deserialize)]
|
||||
#[derive(Routable, Clone)]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
Root {},
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_router::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
fn prepare(path: impl Into<String>) -> VirtualDom {
|
||||
let mut vdom = VirtualDom::new_with_props(App, AppProps { path: path.into() });
|
||||
let _ = vdom.rebuild();
|
||||
return vdom;
|
||||
|
||||
#[derive(Routable, Clone, Serialize, Deserialize)]
|
||||
#[derive(Routable, Clone)]
|
||||
#[rustfmt::skip]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
@@ -36,15 +35,13 @@ fn prepare(path: impl Into<String>) -> VirtualDom {
|
||||
}
|
||||
|
||||
fn App(cx: Scope<AppProps>) -> Element {
|
||||
let cfg = RouterConfiguration {
|
||||
history: Box::new(MemoryHistory::with_initial_path(cx.props.path.clone()).unwrap()),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
render! {
|
||||
h1 { "App" }
|
||||
Router {
|
||||
config: cfg
|
||||
config: {
|
||||
let path = cx.props.path.clone();
|
||||
move || RouterConfiguration::default().history(MemoryHistory::with_initial_path(path).unwrap())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user