Skip to content

Commit

Permalink
egui_router: Remove query from path
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmerlin committed Aug 27, 2024
1 parent c366423 commit c3754ca
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions crates/egui_router/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,10 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
self.history.last().map(|r| r.path.as_str())
}

fn parse_query(path: &str) -> BTreeMap<Cow<str>, Cow<str>> {
let query = path.split_once('?').map(|(_, q)| q);
query
.map(|q| form_urlencoded::parse(q.as_bytes()).collect())
.unwrap_or(BTreeMap::new())
fn parse_path(path: &str) -> (&str, BTreeMap<Cow<str>, Cow<str>>) {
path.split_once('?')
.map(|(path, q)| (path, form_urlencoded::parse(q.as_bytes()).collect()))
.unwrap_or((path, BTreeMap::new()))
}

fn navigate_impl(
Expand All @@ -79,7 +78,7 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
transition_config: TransitionConfig,
new_state: u32,
) -> RouterResult {
let query = Self::parse_query(&path);
let (path, query) = Self::parse_path(&path);

let mut redirect = None;
let result = self.router.at_mut(&path);
Expand All @@ -94,7 +93,7 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
query,
});
self.history.push(RouteState {
path,
path: path.to_string(),
route,
id: ID.fetch_add(1, Ordering::SeqCst),
state: new_state,
Expand Down Expand Up @@ -183,7 +182,7 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
let current_state = self.history.last().map(|r| r.state).unwrap_or(0);
let new_state = current_state;

let query = Self::parse_query(&path);
let (path, query) = Self::parse_path(&path);

let result = match result {
Ok(match_) => match match_.value {
Expand All @@ -196,7 +195,7 @@ impl<State: 'static, H: History + Default> EguiRouter<State, H> {
query,
});
self.history.push(RouteState {
path,
path: path.to_string(),
route,
id: ID.fetch_add(1, Ordering::SeqCst),
state: new_state,
Expand Down

0 comments on commit c3754ca

Please sign in to comment.