feat(ssr): added get_current_url function for SSR support
This commit is contained in:
parent
2bcdea79dc
commit
a35d4d557d
1 changed files with 16 additions and 5 deletions
|
@ -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())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue