Add a warning when Link it called outside of a Router context

This commit is contained in:
Dave Rolsky committed 2022-01-17 15:52:01 -06:00
1 parent 9b282d877b
commit 64080588d0
1 file changed
+10 -3
+10 -3
View File
@@ -41,8 +41,9 @@ pub struct LinkProps<'a> {
} }
pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element { pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element {
let service = cx.consume_context::<RouterService>()?; log::debug!("render Link to {}", cx.props.to);
cx.render(rsx! { if let Some(service) = cx.consume_context::<RouterService>() {
return cx.render(rsx! {
a { a {
href: "{cx.props.to}", href: "{cx.props.to}",
class: format_args!("{}", cx.props.class.unwrap_or("")), class: format_args!("{}", cx.props.class.unwrap_or("")),
@@ -54,5 +55,11 @@ pub fn Link<'a>(cx: Scope<'a, LinkProps<'a>>) -> Element {
&cx.props.children &cx.props.children
} }
}) });
}
log::warn!(
"Attempted to create a Link to {} outside of a Router context",
cx.props.to,
);
None
} }