yew_router/components/
redirect.rsuse wasm_bindgen::UnwrapThrowExt;
use yew::prelude::*;
use crate::hooks::use_navigator;
use crate::Routable;
#[derive(Properties, Clone, PartialEq, Eq)]
pub struct RedirectProps<R: Routable> {
pub to: R,
}
#[function_component(Redirect)]
pub fn redirect<R>(props: &RedirectProps<R>) -> Html
where
R: Routable + 'static,
{
let history = use_navigator().expect_throw("failed to read history.");
let target_route = props.to.clone();
use_effect(move || {
history.push(&target_route);
|| {}
});
Html::default()
}