feat(ssr): added get_current_url function for SSR support

This commit is contained in:
ryan 2025-02-20 15:38:43 +03:00
parent 2bcdea79dc
commit a35d4d557d

View file

@ -84,8 +84,19 @@ pub fn ItemsList(
// Signal to store the fetched property labels // Signal to store the fetched property labels
let (property_labels, set_property_labels) = create_signal(HashMap::<String, String>::new()); let (property_labels, set_property_labels) = create_signal(HashMap::<String, String>::new());
#[cfg(feature = "ssr")]
fn get_current_url() -> String { fn get_current_url() -> String {
window() use leptos::use_context;
use actix_web::HttpRequest;
use_context::<HttpRequest>()
.map(|req| req.uri().to_string())
.unwrap_or_default()
}
#[cfg(not(feature = "ssr"))]
fn get_current_url() -> String {
web_sys::window()
.and_then(|win| win.location().href().ok()) .and_then(|win| win.location().href().ok())
.unwrap_or_else(|| "".to_string()) .unwrap_or_else(|| "".to_string())
} }