Merge pull request #89 from mondeja/fix-core-url-ssr

Fix SSR detection from an url query parameter for `use_color_mode`
This commit is contained in:
Marc-Stefan Cassola 2024-03-12 11:27:10 +00:00 committed by GitHub
commit bfcf0837c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 2 deletions

View file

@ -3,6 +3,12 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
### Fix 🍕
- Fixed SSR detection from an url query parameter for `use_color_mode`.
## [0.10.4] - 2024-03-05
### New Functions 🚀

View file

@ -1,5 +1,6 @@
use leptos::window;
#[cfg_attr(feature = "ssr", allow(dead_code))]
fn get() -> web_sys::Url {
web_sys::Url::new(
&window()
@ -11,10 +12,16 @@ fn get() -> web_sys::Url {
}
pub mod params {
use super::get as current_url;
use cfg_if::cfg_if;
/// Get a URL param value from the URL of the browser
pub fn get(k: &str) -> Option<String> {
current_url().search_params().get(k)
cfg_if! { if #[cfg(feature = "ssr")] {
_ = k;
None
} else {
use super::get as current_url;
current_url().search_params().get(k)
}}
}
}