|
@@ -41,18 +41,25 @@ pub struct LinkProps<'a> {
|
|
|
}
|
|
|
|
|
|
pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element {
|
|
|
- let service = cx.consume_context::<RouterService>()?;
|
|
|
- cx.render(rsx! {
|
|
|
- a {
|
|
|
- href: "{cx.props.to}",
|
|
|
- class: format_args!("{}", cx.props.class.unwrap_or("")),
|
|
|
- id: format_args!("{}", cx.props.id.unwrap_or("")),
|
|
|
- title: format_args!("{}", cx.props.title.unwrap_or("")),
|
|
|
-
|
|
|
- prevent_default: "onclick",
|
|
|
- onclick: move |_| service.push_route(cx.props.to),
|
|
|
-
|
|
|
- &cx.props.children
|
|
|
- }
|
|
|
- })
|
|
|
+ log::debug!("render Link to {}", cx.props.to);
|
|
|
+ if let Some(service) = cx.consume_context::<RouterService>() {
|
|
|
+ return cx.render(rsx! {
|
|
|
+ a {
|
|
|
+ href: "{cx.props.to}",
|
|
|
+ class: format_args!("{}", cx.props.class.unwrap_or("")),
|
|
|
+ id: format_args!("{}", cx.props.id.unwrap_or("")),
|
|
|
+ title: format_args!("{}", cx.props.title.unwrap_or("")),
|
|
|
+
|
|
|
+ prevent_default: "onclick",
|
|
|
+ onclick: move |_| service.push_route(cx.props.to),
|
|
|
+
|
|
|
+ &cx.props.children
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ log::warn!(
|
|
|
+ "Attempted to create a Link to {} outside of a Router context",
|
|
|
+ cx.props.to,
|
|
|
+ );
|
|
|
+ None
|
|
|
}
|