From a1287e8e8cb03d513d3a1976164404eb641eeea3 Mon Sep 17 00:00:00 2001 From: Kryesh <28243483+kryesh@users.noreply.github.com> Date: Thu, 11 Apr 2024 23:10:18 +1000 Subject: [PATCH] Add 'create_query_signal_with_options' version of 'create_query_signal' --- router/src/hooks.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/router/src/hooks.rs b/router/src/hooks.rs index 41ceb52cf5..7a9babd42c 100644 --- a/router/src/hooks.rs +++ b/router/src/hooks.rs @@ -47,6 +47,17 @@ use std::{rc::Rc, str::FromStr}; pub fn create_query_signal( key: impl Into>, ) -> (Memo>, SignalSetter>) +where + T: FromStr + ToString + PartialEq, +{ + create_query_signal_with_options::(key, NavigateOptions::default()) +} + +#[track_caller] +pub fn create_query_signal_with_options( + key: impl Into>, + nav_options: NavigateOptions, +) -> (Memo>, SignalSetter>) where T: FromStr + ToString + PartialEq, { @@ -65,6 +76,7 @@ where let set = SignalSetter::map(move |value: Option| { let mut new_query_map = query_map.get(); + let nav_options = nav_options.clone(); match value { Some(value) => { new_query_map.insert(key.to_string(), value.to_string()); @@ -77,7 +89,7 @@ where let path = location.pathname.get_untracked(); let hash = location.hash.get_untracked(); let new_url = format!("{path}{qs}{hash}"); - navigate(&new_url, NavigateOptions::default()); + navigate(&new_url, nav_options); }); (get, set)