mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-10 06:34:20 +00:00
fix CI
This commit is contained in:
parent
577f99e68c
commit
a9307e57e6
23 changed files with 160 additions and 164 deletions
|
@ -29,9 +29,9 @@ fn app(cx: Scope) -> Element {
|
|||
render! {
|
||||
Router {
|
||||
config: || RouterConfig::default().on_update(|state|{
|
||||
(state.current() == Route::Index {}).then(|| {
|
||||
(state.current() == Route::Index {}).then_some(
|
||||
NavigationTarget::Internal(Route::Home {})
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
//! Tiny CRM: A port of the Yew CRM example to Dioxus.
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_router::prelude::*;
|
||||
|
||||
|
@ -10,6 +7,17 @@ fn main() {
|
|||
dioxus_desktop::launch(App);
|
||||
}
|
||||
|
||||
#[derive(Routable, Clone)]
|
||||
#[rustfmt::skip]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
ClientList {},
|
||||
#[route("/new")]
|
||||
ClientAdd {},
|
||||
#[route("/settings")]
|
||||
Settings {},
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct Client {
|
||||
pub first_name: String,
|
||||
|
@ -17,22 +25,10 @@ pub struct Client {
|
|||
pub description: String,
|
||||
}
|
||||
|
||||
type ClientContext = Arc<Mutex<Vec<Client>>>;
|
||||
type ClientContext = Vec<Client>;
|
||||
|
||||
fn App(cx: Scope) -> Element {
|
||||
use_router(cx, &RouterConfiguration::default, &|| {
|
||||
Segment::content(comp(ClientList))
|
||||
.fixed(
|
||||
"new",
|
||||
Route::content(comp(ClientAdd)).name::<ClientAddName>(),
|
||||
)
|
||||
.fixed(
|
||||
"settings",
|
||||
Route::content(comp(Settings)).name::<SettingsName>(),
|
||||
)
|
||||
});
|
||||
|
||||
use_context_provider::<ClientContext>(cx, Default::default);
|
||||
use_shared_state_provider::<ClientContext>(cx, Default::default);
|
||||
|
||||
render! {
|
||||
link {
|
||||
|
@ -50,28 +46,29 @@ fn App(cx: Scope) -> Element {
|
|||
|
||||
h1 { "Dioxus CRM Example" }
|
||||
|
||||
Outlet { }
|
||||
Router {}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn ClientList(cx: Scope) -> Element {
|
||||
let clients = use_context::<ClientContext>(cx).unwrap();
|
||||
let clients = use_shared_state::<ClientContext>(cx).unwrap();
|
||||
|
||||
cx.render(rsx! {
|
||||
h2 { "List of Clients" }
|
||||
|
||||
Link {
|
||||
target: named::<ClientAddName>(),
|
||||
target: Route::ClientAdd {},
|
||||
class: "pure-button pure-button-primary",
|
||||
"Add Client"
|
||||
}
|
||||
Link {
|
||||
target: named::<SettingsName>(),
|
||||
target: Route::Settings {},
|
||||
class: "pure-button",
|
||||
"Settings"
|
||||
}
|
||||
|
||||
clients.lock().unwrap().iter().map(|client| rsx! {
|
||||
clients.read().iter().map(|client| rsx! {
|
||||
div {
|
||||
class: "client",
|
||||
style: "margin-bottom: 50px",
|
||||
|
@ -83,14 +80,14 @@ fn ClientList(cx: Scope) -> Element {
|
|||
})
|
||||
}
|
||||
|
||||
struct ClientAddName;
|
||||
#[inline_props]
|
||||
fn ClientAdd(cx: Scope) -> Element {
|
||||
let clients = use_context::<ClientContext>(cx).unwrap();
|
||||
let clients = use_shared_state::<ClientContext>(cx).unwrap();
|
||||
let first_name = use_state(cx, String::new);
|
||||
let last_name = use_state(cx, String::new);
|
||||
let description = use_state(cx, String::new);
|
||||
|
||||
let navigator = use_navigate(cx).unwrap();
|
||||
let navigator = use_navigator(cx);
|
||||
|
||||
cx.render(rsx! {
|
||||
h2 { "Add new Client" }
|
||||
|
@ -98,7 +95,7 @@ fn ClientAdd(cx: Scope) -> Element {
|
|||
form {
|
||||
class: "pure-form pure-form-aligned",
|
||||
onsubmit: move |_| {
|
||||
let mut clients = clients.lock().unwrap();
|
||||
let mut clients = clients.write();
|
||||
|
||||
clients.push(Client {
|
||||
first_name: first_name.to_string(),
|
||||
|
@ -106,7 +103,7 @@ fn ClientAdd(cx: Scope) -> Element {
|
|||
description: description.to_string(),
|
||||
});
|
||||
|
||||
navigator.push(named::<RootIndex>());
|
||||
navigator.push(Route::ClientList {});
|
||||
},
|
||||
|
||||
fieldset {
|
||||
|
@ -164,7 +161,7 @@ fn ClientAdd(cx: Scope) -> Element {
|
|||
"Save"
|
||||
}
|
||||
Link {
|
||||
target: named::<RootIndex>(),
|
||||
target: Route::ClientList {},
|
||||
class: "pure-button pure-button-primary red",
|
||||
"Cancel"
|
||||
}
|
||||
|
@ -176,9 +173,9 @@ fn ClientAdd(cx: Scope) -> Element {
|
|||
})
|
||||
}
|
||||
|
||||
struct SettingsName;
|
||||
#[inline_props]
|
||||
fn Settings(cx: Scope) -> Element {
|
||||
let clients = use_context::<ClientContext>(cx).unwrap();
|
||||
let clients = use_shared_state::<ClientContext>(cx).unwrap();
|
||||
|
||||
cx.render(rsx! {
|
||||
h2 { "Settings" }
|
||||
|
@ -186,14 +183,14 @@ fn Settings(cx: Scope) -> Element {
|
|||
button {
|
||||
class: "pure-button pure-button-primary red",
|
||||
onclick: move |_| {
|
||||
let mut clients = clients.lock().unwrap();
|
||||
let mut clients = clients.write();
|
||||
clients.clear();
|
||||
},
|
||||
"Remove all Clients"
|
||||
}
|
||||
|
||||
Link {
|
||||
target: named::<RootIndex>(),
|
||||
target: Route::ClientList {},
|
||||
class: "pure-button",
|
||||
"Go back"
|
||||
}
|
||||
|
|
|
@ -17,13 +17,27 @@ fn main() {
|
|||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
use_router(cx, &RouterConfiguration::default, &|| {
|
||||
Segment::content(comp(Home))
|
||||
.fixed("games", comp(Games))
|
||||
.fixed("play", comp(Play))
|
||||
.fixed("settings", comp(Settings))
|
||||
});
|
||||
render! {
|
||||
Router {}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Routable, Clone)]
|
||||
#[rustfmt::skip]
|
||||
enum Route {
|
||||
#[layout(Footer)]
|
||||
#[route("/")]
|
||||
Home {},
|
||||
#[route("/games")]
|
||||
Games {},
|
||||
#[route("/play")]
|
||||
Play {},
|
||||
#[route("/settings")]
|
||||
Settings {},
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Footer(cx: Scope) -> Element {
|
||||
render! {
|
||||
div {
|
||||
Outlet { }
|
||||
|
@ -34,28 +48,32 @@ fn app(cx: Scope) -> Element {
|
|||
|
||||
nav {
|
||||
ul {
|
||||
li { Link { target: "/", "Home" } }
|
||||
li { Link { target: "/games", "Games" } }
|
||||
li { Link { target: "/play", "Play" } }
|
||||
li { Link { target: "/settings", "Settings" } }
|
||||
li { Link { target: Route::Home {}, "Home" } }
|
||||
li { Link { target: Route::Games {}, "Games" } }
|
||||
li { Link { target: Route::Play {}, "Play" } }
|
||||
li { Link { target: Route::Settings {}, "Settings" } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Home(cx: Scope) -> Element {
|
||||
render!("Home")
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Games(cx: Scope) -> Element {
|
||||
render!("Games")
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Play(cx: Scope) -> Element {
|
||||
render!("Play")
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Settings(cx: Scope) -> Element {
|
||||
render!("Settings")
|
||||
}
|
||||
|
|
|
@ -8,10 +8,6 @@ fn main() {
|
|||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
use_router(cx, &RouterConfiguration::default, &|| {
|
||||
Segment::content(comp(Home)).fixed("settings", comp(Settings))
|
||||
});
|
||||
|
||||
cx.render(rsx! (
|
||||
div {
|
||||
p {
|
||||
|
@ -27,20 +23,39 @@ fn app(cx: Scope) -> Element {
|
|||
}
|
||||
}
|
||||
div {
|
||||
Outlet { }
|
||||
p { "----"}
|
||||
ul {
|
||||
Link { target: "/", li { "Router link to home" } },
|
||||
Link { target: "/settings", li { "Router link to settings" } },
|
||||
}
|
||||
Router {}
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
#[derive(Routable, Clone)]
|
||||
#[rustfmt::skip]
|
||||
enum Route {
|
||||
#[layout(Header)]
|
||||
#[route("/")]
|
||||
Home {},
|
||||
#[route("/settings")]
|
||||
Settings {},
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Header(cx: Scope) -> Element {
|
||||
render! {
|
||||
h1 { "Your app here" }
|
||||
ul {
|
||||
li { Link { target: Route::Home {}, "home" } }
|
||||
li { Link { target: Route::Settings {}, "settings" } }
|
||||
}
|
||||
Outlet {}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Home(cx: Scope) -> Element {
|
||||
render!(h1 { "Home" })
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Settings(cx: Scope) -> Element {
|
||||
render!(h1 { "Settings" })
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ use dioxus_router::prelude::*;
|
|||
fn main() {
|
||||
simple_logger::SimpleLogger::new()
|
||||
.with_level(log::LevelFilter::Debug)
|
||||
.with_module_level("dioxus_router", log::LevelFilter::Trace)
|
||||
.with_module_level("dioxus", log::LevelFilter::Trace)
|
||||
.init()
|
||||
.unwrap();
|
||||
|
@ -14,58 +13,69 @@ fn main() {
|
|||
}
|
||||
|
||||
fn app(cx: Scope) -> Element {
|
||||
use_router(cx, &RouterConfiguration::default, &|| {
|
||||
Segment::content(comp(Home))
|
||||
.fixed(
|
||||
"blog",
|
||||
Route::empty().nested(
|
||||
Segment::content(comp(BlogList)).catch_all((comp(BlogPost), PostId {})),
|
||||
),
|
||||
)
|
||||
.fixed("oranges", comp(Oranges))
|
||||
.fixed("apples", "/oranges")
|
||||
});
|
||||
|
||||
render! {
|
||||
h1 { "Your app here" }
|
||||
ul {
|
||||
li { Link { target: "/", "home" } }
|
||||
li { Link { target: "/blog", "blog" } }
|
||||
li { Link { target: "/blog/tim", "tims' blog" } }
|
||||
li { Link { target: "/blog/bill", "bills' blog" } }
|
||||
li { Link { target: "/blog/james", "james amazing' blog" } }
|
||||
li { Link { target: "/apples", "go to apples" } }
|
||||
}
|
||||
Outlet { }
|
||||
Router {}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Routable, Clone)]
|
||||
#[rustfmt::skip]
|
||||
enum Route {
|
||||
#[layout(NavBar)]
|
||||
#[route("/")]
|
||||
Home {},
|
||||
#[nest("/new")]
|
||||
#[route("/")]
|
||||
BlogList {},
|
||||
#[route("/:post")]
|
||||
BlogPost {
|
||||
post: String,
|
||||
},
|
||||
#[end_nest]
|
||||
#[route("/oranges")]
|
||||
Oranges {},
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn NavBar(cx: Scope) -> Element {
|
||||
render! {
|
||||
h1 { "Your app here" }
|
||||
ul {
|
||||
li { Link { target: Route::Home {}, "home" } }
|
||||
li { Link { target: Route::BlogList {}, "blog" } }
|
||||
li { Link { target: Route::BlogPost { post: "tim".into() }, "tims' blog" } }
|
||||
li { Link { target: Route::BlogPost { post: "bill".into() }, "bills' blog" } }
|
||||
li { Link { target: Route::BlogPost { post: "james".into() }, "james amazing' blog" } }
|
||||
}
|
||||
Outlet {}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Home(cx: Scope) -> Element {
|
||||
log::debug!("rendering home {:?}", cx.scope_id());
|
||||
render! { h1 { "Home" } }
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn BlogList(cx: Scope) -> Element {
|
||||
log::debug!("rendering blog list {:?}", cx.scope_id());
|
||||
render! { div { "Blog List" } }
|
||||
}
|
||||
|
||||
struct PostId;
|
||||
fn BlogPost(cx: Scope) -> Element {
|
||||
let Some(id) = use_route(cx)?.parameter::<PostId>() else {
|
||||
return render!(div { "No blog post id" });
|
||||
};
|
||||
|
||||
log::debug!("rendering blog post {}", id);
|
||||
#[inline_props]
|
||||
fn BlogPost(cx: Scope, post: String) -> Element {
|
||||
log::debug!("rendering blog post {}", post);
|
||||
|
||||
render! {
|
||||
div {
|
||||
h3 { "blog post: {id:?}" }
|
||||
Link { target: "/blog/", "back to blog list" }
|
||||
h3 { "blog post: {post}" }
|
||||
Link { target: Route::BlogList {}, "back to blog list" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
fn Oranges(cx: Scope) -> Element {
|
||||
render!("Oranges are not apples!")
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ fn formatting_compiles() {
|
|||
// function calls in formatings work
|
||||
assert_eq!(
|
||||
format_args_f!("{x.borrow():?}").to_string(),
|
||||
format!("{:?}", x.borrow())
|
||||
format!("{:?}", x)
|
||||
);
|
||||
|
||||
// allows duplicate format args
|
||||
|
|
|
@ -18,7 +18,7 @@ static REGISTERED_SERVER_FUNCTIONS: once_cell::sync::Lazy<
|
|||
/// The registry of all Dioxus server functions.
|
||||
pub struct DioxusServerFnRegistry;
|
||||
|
||||
#[cfg(any(feature = "ssr"))]
|
||||
#[cfg(feature = "ssr")]
|
||||
impl server_fn::ServerFunctionRegistry<DioxusServerContext> for DioxusServerFnRegistry {
|
||||
type Error = ServerRegistrationFnError;
|
||||
|
||||
|
|
|
@ -21,10 +21,9 @@ use std::{
|
|||
};
|
||||
use std::{rc::Rc, sync::RwLock};
|
||||
use style_attributes::StyleModifier;
|
||||
use taffy::Taffy;
|
||||
pub use taffy::{geometry::Point, prelude::*};
|
||||
use tokio::select;
|
||||
use tui::{backend::CrosstermBackend, layout::Rect, Terminal};
|
||||
use tui::{backend::CrosstermBackend, Terminal};
|
||||
|
||||
mod config;
|
||||
mod focus;
|
||||
|
@ -160,8 +159,8 @@ pub fn render<R: Driver>(
|
|||
|
||||
if !to_rerender.is_empty() || updated {
|
||||
updated = false;
|
||||
fn resize(dims: Rect, taffy: &mut Taffy, rdom: &RealDom) {
|
||||
let width = screen_to_layout_space(dims.width);
|
||||
fn resize(dims: tui::layout::Rect, taffy: &mut Taffy, rdom: &RealDom) {
|
||||
let width: f32 = screen_to_layout_space(dims.width);
|
||||
let height = screen_to_layout_space(dims.height);
|
||||
let root_node = rdom
|
||||
.get(rdom.root_id())
|
||||
|
@ -202,7 +201,7 @@ pub fn render<R: Driver>(
|
|||
} else {
|
||||
let rdom = rdom.read().unwrap();
|
||||
resize(
|
||||
Rect {
|
||||
tui::layout::Rect {
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 1000,
|
||||
|
|
|
@ -30,11 +30,10 @@ expressiveness.
|
|||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_router::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::str::FromStr;
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Routable)]
|
||||
#[derive(Clone, Debug, PartialEq, Routable)]
|
||||
enum Route {
|
||||
#[nest("/blog")]
|
||||
#[layout(Blog)]
|
||||
|
|
|
@ -24,8 +24,7 @@ pub struct GenericHistoryButtonProps<'a> {
|
|||
/// ```rust
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable)]
|
||||
/// #[derive(Clone, Routable)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
@ -98,8 +97,7 @@ pub fn GenericGoBackButton<'a, R: Routable>(
|
|||
/// ```rust
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable)]
|
||||
/// #[derive(Clone, Routable)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
|
|
@ -83,9 +83,8 @@ impl<R: Routable> Debug for GenericLinkProps<'_, R> {
|
|||
/// ```rust
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
///
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable)]
|
||||
/// #[derive(Clone, Routable)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
|
|
@ -15,9 +15,8 @@ use dioxus::prelude::*;
|
|||
/// # Example
|
||||
/// ```rust
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable)]
|
||||
/// #[derive(Clone, Routable)]
|
||||
/// #[rustfmt::skip]
|
||||
/// enum Route {
|
||||
/// #[nest("/wrap")]
|
||||
|
@ -59,10 +58,7 @@ use dioxus::prelude::*;
|
|||
/// # fn App(cx: Scope) -> Element {
|
||||
/// # render! {
|
||||
/// # Router {
|
||||
/// # config: RouterConfiguration {
|
||||
/// # history: Box::new(MemoryHistory::with_initial_path("/wrap").unwrap()),
|
||||
/// # ..Default::default()
|
||||
/// # }
|
||||
/// # config: || RouterConfig::default().history(MemoryHistory::with_initial_path(Route::Child {}))
|
||||
/// # }
|
||||
/// # }
|
||||
/// # }
|
||||
|
|
|
@ -22,17 +22,6 @@ struct MutableRouterState<R>
|
|||
where
|
||||
R: Routable,
|
||||
{
|
||||
/// Whether there is a previous page to navigate back to.
|
||||
///
|
||||
/// Even if this is [`true`], there might not be a previous page. However, it is nonetheless
|
||||
/// safe to tell the router to go back.
|
||||
can_go_back: bool,
|
||||
/// Whether there is a future page to navigate forward to.
|
||||
///
|
||||
/// Even if this is [`true`], there might not be a future page. However, it is nonetheless safe
|
||||
/// to tell the router to go forward.
|
||||
can_go_forward: bool,
|
||||
|
||||
/// The current prefix.
|
||||
prefix: Option<String>,
|
||||
|
||||
|
@ -76,8 +65,6 @@ where
|
|||
R: Clone,
|
||||
{
|
||||
let state = Arc::new(RwLock::new(MutableRouterState {
|
||||
can_go_back: false,
|
||||
can_go_forward: false,
|
||||
prefix: Default::default(),
|
||||
history: cfg.history,
|
||||
unresolved_error: None,
|
||||
|
@ -112,13 +99,13 @@ where
|
|||
/// Check whether there is a previous page to navigate back to.
|
||||
#[must_use]
|
||||
pub fn can_go_back(&self) -> bool {
|
||||
self.state.read().unwrap().can_go_back
|
||||
self.state.read().unwrap().history.can_go_back()
|
||||
}
|
||||
|
||||
/// Check whether there is a future page to navigate forward to.
|
||||
#[must_use]
|
||||
pub fn can_go_forward(&self) -> bool {
|
||||
self.state.read().unwrap().can_go_forward
|
||||
self.state.read().unwrap().history.can_go_forward()
|
||||
}
|
||||
|
||||
/// Go back to the previous location.
|
||||
|
|
|
@ -19,13 +19,12 @@ where
|
|||
///
|
||||
/// ```rust
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # #[inline_props]
|
||||
/// # fn Index(cx: Scope) -> Element { todo!() }
|
||||
/// # #[inline_props]
|
||||
/// # fn OtherPage(cx: Scope) -> Element { todo!() }
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable, Debug, PartialEq)]
|
||||
/// #[derive(Clone, Routable, Debug, PartialEq)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
@ -33,7 +32,7 @@ where
|
|||
/// OtherPage {},
|
||||
/// }
|
||||
///
|
||||
/// let mut history = MemoryHistory::<Route>::with_initial_path(Route::Index {}).unwrap();
|
||||
/// let mut history = MemoryHistory::<Route>::with_initial_path(Route::Index {});
|
||||
/// assert_eq!(history.current_route(), Route::Index {});
|
||||
/// assert_eq!(history.can_go_back(), false);
|
||||
/// ```
|
||||
|
|
|
@ -47,13 +47,12 @@ pub trait HistoryProvider<R: Routable> {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # #[inline_props]
|
||||
/// # fn Index(cx: Scope) -> Element { todo!() }
|
||||
/// # #[inline_props]
|
||||
/// # fn OtherPage(cx: Scope) -> Element { todo!() }
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable, Debug, PartialEq)]
|
||||
/// #[derive(Clone, Routable, Debug, PartialEq)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
@ -86,11 +85,10 @@ pub trait HistoryProvider<R: Routable> {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # #[inline_props]
|
||||
/// # fn Index(cx: Scope) -> Element { todo!() }
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable, Debug, PartialEq)]
|
||||
/// #[derive(Clone, Routable, Debug, PartialEq)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
@ -113,13 +111,12 @@ pub trait HistoryProvider<R: Routable> {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # #[inline_props]
|
||||
/// # fn Index(cx: Scope) -> Element { todo!() }
|
||||
/// # #[inline_props]
|
||||
/// # fn OtherPage(cx: Scope) -> Element { todo!() }
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable, Debug, PartialEq)]
|
||||
/// #[derive(Clone, Routable, Debug, PartialEq)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
@ -146,13 +143,12 @@ pub trait HistoryProvider<R: Routable> {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # #[inline_props]
|
||||
/// # fn Index(cx: Scope) -> Element { todo!() }
|
||||
/// # #[inline_props]
|
||||
/// # fn OtherPage(cx: Scope) -> Element { todo!() }
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable, Debug, PartialEq)]
|
||||
/// #[derive(Clone, Routable, Debug, PartialEq)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
@ -180,13 +176,12 @@ pub trait HistoryProvider<R: Routable> {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # #[inline_props]
|
||||
/// # fn Index(cx: Scope) -> Element { todo!() }
|
||||
/// # #[inline_props]
|
||||
/// # fn OtherPage(cx: Scope) -> Element { todo!() }
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable, Debug, PartialEq)]
|
||||
/// #[derive(Clone, Routable, Debug, PartialEq)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
@ -214,13 +209,12 @@ pub trait HistoryProvider<R: Routable> {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # #[inline_props]
|
||||
/// # fn Index(cx: Scope) -> Element { todo!() }
|
||||
/// # #[inline_props]
|
||||
/// # fn OtherPage(cx: Scope) -> Element { todo!() }
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable, Debug, PartialEq)]
|
||||
/// #[derive(Clone, Routable, Debug, PartialEq)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
@ -244,13 +238,12 @@ pub trait HistoryProvider<R: Routable> {
|
|||
///
|
||||
/// ```rust
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # #[inline_props]
|
||||
/// # fn Index(cx: Scope) -> Element { todo!() }
|
||||
/// # #[inline_props]
|
||||
/// # fn OtherPage(cx: Scope) -> Element { todo!() }
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable, Debug, PartialEq)]
|
||||
/// #[derive(Clone, Routable, Debug, PartialEq)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
|
|
@ -12,8 +12,7 @@ use crate::{
|
|||
/// ```rust
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable)]
|
||||
/// #[derive(Clone, Routable)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
|
|
@ -17,10 +17,9 @@ use crate::utils::use_router_internal::use_router_internal;
|
|||
/// # Example
|
||||
/// ```rust
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # use dioxus_router::{prelude::*};
|
||||
///
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable)]
|
||||
/// #[derive(Clone, Routable)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
|
|
@ -19,12 +19,11 @@ pub enum NavigationTarget<R: Routable> {
|
|||
/// # use dioxus::prelude::*;
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use dioxus_router::navigation::NavigationTarget;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # #[inline_props]
|
||||
/// # fn Index(cx: Scope) -> Element {
|
||||
/// # todo!()
|
||||
/// # }
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable, PartialEq, Debug)]
|
||||
/// #[derive(Clone, Routable, PartialEq, Debug)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
@ -40,12 +39,11 @@ pub enum NavigationTarget<R: Routable> {
|
|||
/// # use dioxus::prelude::*;
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use dioxus_router::navigation::NavigationTarget;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # #[inline_props]
|
||||
/// # fn Index(cx: Scope) -> Element {
|
||||
/// # todo!()
|
||||
/// # }
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable, PartialEq, Debug)]
|
||||
/// #[derive(Clone, Routable, PartialEq, Debug)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
|
|
|
@ -12,18 +12,17 @@ use crate::prelude::*;
|
|||
/// This implements [`Default`] and follows the builder pattern, so you can use it like this:
|
||||
/// ```rust,no_run
|
||||
/// # use dioxus_router::prelude::*;
|
||||
/// # use serde::{Deserialize, Serialize};
|
||||
/// # use dioxus::prelude::*;
|
||||
/// # #[inline_props]
|
||||
/// # fn Index(cx: Scope) -> Element {
|
||||
/// # todo!()
|
||||
/// # }
|
||||
/// #[derive(Clone, Serialize, Deserialize, Routable)]
|
||||
/// #[derive(Clone, Routable)]
|
||||
/// enum Route {
|
||||
/// #[route("/")]
|
||||
/// Index {},
|
||||
/// }
|
||||
/// let cfg = RouterConfig::default().history(WebHistory<Route>::default());
|
||||
/// let cfg = RouterConfig::default().history(WebHistory::<Route>::default());
|
||||
/// ```
|
||||
pub struct RouterConfig<R: Routable> {
|
||||
pub(crate) failure_external_navigation: fn(Scope) -> Element,
|
||||
|
|
|
@ -34,7 +34,7 @@ where
|
|||
render! {
|
||||
h1 { "App" }
|
||||
GenericRouter::<R> {
|
||||
config: || RouterConfiguration::default().history(MemoryHistory::default())
|
||||
config: || RouterConfig::default().history(MemoryHistory::default())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ fn prepare(path: impl Into<String>) -> VirtualDom {
|
|||
h1 { "App" }
|
||||
Router {
|
||||
config: {
|
||||
let path = cx.props.path.clone();
|
||||
move || RouterConfiguration::default().history(MemoryHistory::with_initial_path(path).unwrap())
|
||||
let path = cx.props.path.parse().unwrap();
|
||||
move || RouterConfig::default().history(MemoryHistory::with_initial_path(path))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,15 @@
|
|||
#![cfg(feature = "wasm_test")]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_router::prelude::*;
|
||||
use gloo::utils::document;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::str::FromStr;
|
||||
use wasm_bindgen_test::*;
|
||||
|
||||
wasm_bindgen_test_configure!(run_in_browser);
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Routable)]
|
||||
#[derive(Clone, Debug, PartialEq, Routable)]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
Home {},
|
||||
|
@ -25,12 +21,7 @@ enum Route {
|
|||
}
|
||||
|
||||
fn App(cx: Scope) -> Element {
|
||||
render!(Router {
|
||||
config: RouterConfiguration {
|
||||
history: Box::<WebHistory<Route>>::default(),
|
||||
..Default::default()
|
||||
}
|
||||
})
|
||||
render!(Router {})
|
||||
}
|
||||
|
||||
#[inline_props]
|
||||
|
|
Loading…
Reference in a new issue