diff --git a/packages/sycamore-router/src/router.rs b/packages/sycamore-router/src/router.rs index 7ee785a6d..6a7719c57 100644 --- a/packages/sycamore-router/src/router.rs +++ b/packages/sycamore-router/src/router.rs @@ -153,3 +153,57 @@ pub fn navigate(url: &str) { fn meta_keys_pressed(kb_event: &KeyboardEvent) -> bool { kb_event.meta_key() || kb_event.ctrl_key() || kb_event.shift_key() || kb_event.alt_key() } + +#[cfg(test)] +mod tests { + use sycamore::prelude::*; + + use super::*; + + #[test] + fn static_router() { + #[derive(Route)] + enum Routes { + #[to("/")] + Home, + #[to("/about")] + About, + #[not_found] + NotFound, + } + + #[component(Comp)] + fn comp(path: String) -> Template { + template! { + StaticRouter((path, |route: Routes| { + match route { + Routes::Home => template! { + "Home" + }, + Routes::About => template! { + "About" + }, + Routes::NotFound => template! { + "Not Found" + } + } + })) + } + } + + assert_eq!( + sycamore::render_to_string(|| template! { Comp("/".to_string()) }), + "Home" + ); + + assert_eq!( + sycamore::render_to_string(|| template! { Comp("/about".to_string()) }), + "About" + ); + + assert_eq!( + sycamore::render_to_string(|| template! { Comp("/404".to_string()) }), + "Not Found" + ); + } +} diff --git a/website/src/content.rs b/website/src/content.rs index 505b127cf..8dff8f2a6 100644 --- a/website/src/content.rs +++ b/website/src/content.rs @@ -127,7 +127,7 @@ pub fn content( p { "This is unreleased documentation for Sycamore next version." } p { "For up-to-date documentation, see the " - a(href=format!("/docs/{}/getting_started/hello_world", crate::LATEST_MAJOR_VERSION)) { + a(href=format!("/docs/{}/getting_started/installation", crate::LATEST_MAJOR_VERSION)) { "latest version" } " (" (crate::LATEST_MAJOR_VERSION) ")." @@ -140,7 +140,7 @@ pub fn content( p { "This is outdated documentation for Sycamore." } p { "For up-to-date documentation, see the " - a(href=format!("/docs/{}/getting_started/hello_world", crate::LATEST_MAJOR_VERSION)) { + a(href=format!("/docs/{}/getting_started/installation", crate::LATEST_MAJOR_VERSION)) { "latest version" } " (" (crate::LATEST_MAJOR_VERSION) ")."