Improve `router` feature warning

This commit is contained in:
Greg Johnston 2023-01-10 21:10:27 -05:00
parent 7d7a96d9bc
commit 46254a18f3
1 changed files with 9 additions and 1 deletions

View File

@ -87,7 +87,15 @@ impl RouterContext {
let history = use_context::<RouterIntegrationContext>(cx)
.unwrap_or_else(|| RouterIntegrationContext(Rc::new(crate::BrowserIntegration {})));
} else {
let history = use_context::<RouterIntegrationContext>(cx).expect("You must call provide_context::<RouterIntegrationContext>(cx, ...) somewhere above the <Router/>.");
let history = use_context::<RouterIntegrationContext>(cx).unwrap_or_else(|| {
let msg = "No router integration found.\n\nIf you are using this in the browser, \
you should enable `feature = [\"csr\"]` or `feature = [\"hydrate\"] in your \
`leptos_router` import.\n\nIf you are using this on the server without a \
Leptos server integration, you must call provide_context::<RouterIntegrationContext>(cx, ...) \
somewhere above the <Router/>.";
leptos::debug_warn!("{}", msg);
panic!("{}", msg);
});
}
};