fix: Demo switch version (#155)

This commit is contained in:
luoxiaozero 2024-03-29 16:49:07 +08:00 committed by GitHub
parent c3fdf5fcb0
commit 6cc68ba398
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -17,12 +17,12 @@ pub fn SwitchVersion() -> impl IntoView {
cfg_if::cfg_if! { cfg_if::cfg_if! {
if #[cfg(any(feature = "csr", feature = "hydrate"))] { if #[cfg(any(feature = "csr", feature = "hydrate"))] {
let location = window().location(); let location = window().location();
let host = location.host().ok(); let origin = location.origin().ok();
let version = RwSignal::new(host); let version = RwSignal::new(origin);
let _ = version.watch(move |host| { let _ = version.watch(move |origin| {
if let Some(host) = host { if let Some(origin) = origin {
let pathname = location.pathname().unwrap_or_default(); let pathname = location.pathname().unwrap_or_default();
let href = format!("{}{}", host, pathname); let href = format!("{}{}", origin, pathname);
let _ = location.set_href(&href); let _ = location.set_href(&href);
} }
}); });