dioxus/packages/router/src/lib.rs

50 lines
1.3 KiB
Rust
Raw Normal View History

2021-11-03 04:35:56 +00:00
mod utils;
2021-12-01 03:48:05 +00:00
use std::{cell::RefCell, rc::Rc};
2021-11-03 04:35:56 +00:00
use dioxus_core as dioxus;
use dioxus_core::prelude::*;
2021-12-01 03:48:05 +00:00
use dioxus_core_macro::{rsx, Props};
2021-11-03 04:35:56 +00:00
use dioxus_html as dioxus_elements;
2021-12-19 04:03:59 +00:00
// use wasm_bindgen::{JsCast, JsValue};
2021-11-03 04:35:56 +00:00
2021-11-22 20:22:42 +00:00
use crate::utils::strip_slash_suffix;
2021-11-03 04:35:56 +00:00
2021-11-22 20:22:42 +00:00
pub trait Routable: 'static + Send + Clone + PartialEq {}
impl<T> Routable for T where T: 'static + Send + Clone + PartialEq {}
2021-11-19 05:49:04 +00:00
2021-11-03 04:35:56 +00:00
#[derive(Props)]
2021-12-15 02:46:19 +00:00
pub struct LinkProps<'a, R: Routable> {
2021-11-03 04:35:56 +00:00
to: R,
2021-11-22 20:22:42 +00:00
/// The url that gets pushed to the history stack
///
/// You can either put it your own inline method or just autoderive the route using `derive(Routable)`
///
/// ```rust
///
/// Link { to: Route::Home, href: |_| "home".to_string() }
///
/// // or
///
/// Link { to: Route::Home, href: Route::as_url }
///
/// ```
href: fn(&R) -> String,
#[builder(default)]
2021-12-15 02:46:19 +00:00
children: Element<'a>,
2021-11-03 04:35:56 +00:00
}
2021-12-15 02:46:19 +00:00
pub fn Link<'a, R: Routable>(cx: Scope<'a, LinkProps<'a, R>>) -> Element {
2021-12-19 04:03:59 +00:00
let service = todo!();
// let service: todo!() = use_router_service::<R>(&cx)?;
// cx.render(rsx! {
// a {
// href: format_args!("{}", (cx.props.href)(&cx.props.to)),
// onclick: move |_| service.push_route(cx.props.to.clone()),
// // todo!() {&cx.props.children},
// }
// })
2021-11-03 04:35:56 +00:00
}