* [yew-devel] [PATCH yew-widget-toolkit 1/2] state: navigation: add 'replace_relative_route' to NavigationContextExt
@ 2025-12-16 9:55 Dominik Csapak
2025-12-16 9:55 ` [yew-devel] [PATCH yew-widget-toolkit 2/2] widget: tab panel: improve route handling on creation Dominik Csapak
2025-12-16 10:35 ` [yew-devel] applied: [PATCH yew-widget-toolkit 1/2] state: navigation: add 'replace_relative_route' to NavigationContextExt Dietmar Maurer
0 siblings, 2 replies; 4+ messages in thread
From: Dominik Csapak @ 2025-12-16 9:55 UTC (permalink / raw)
To: yew-devel
so we can not only push new relative routes, but also replace the
current one.
To not duplicate that much code, refactor the absolute path generation
out, this even avoids some duplication we already had.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/state/navigation_container.rs | 55 ++++++++++++++++---------------
1 file changed, 28 insertions(+), 27 deletions(-)
diff --git a/src/state/navigation_container.rs b/src/state/navigation_container.rs
index eced509..b9090eb 100644
--- a/src/state/navigation_container.rs
+++ b/src/state/navigation_container.rs
@@ -243,10 +243,25 @@ pub trait NavigationContextExt {
fn nav_context(&self) -> Option<NavigationContext>;
/// Returns the full route to this context ("/parent_path/path").
fn full_path(&self) -> Option<String>;
- /// Change the current route to "/parent_path/path".
+ /// Push a new route "/parent_path/path".
///
/// Only works if the scope provides a [Navigator](yew_router::navigator::Navigator).
fn push_relative_route(&self, path: &str);
+ /// Replace the current route with "/parent_path/path".
+ ///
+ /// Only works if the scope provides a [Navigator](yew_router::navigator::Navigator).
+ fn replace_relative_route(&self, path: &str);
+}
+
+fn get_new_absolute_path<COMP: Component>(scope: &yew::html::Scope<COMP>, path: &str) -> String {
+ let path = normalize_segment(path);
+ let parent_path = scope
+ .context::<NavigationContext>(Callback::from(|_| {}))
+ .and_then(|(ctx, _)| ctx.parent_path);
+ match parent_path {
+ Some(parent_path) => format!("{}/{}", parent_path, path),
+ None => format!("/{}", path),
+ }
}
impl<COMP: Component> NavigationContextExt for yew::html::Scope<COMP> {
@@ -260,32 +275,18 @@ impl<COMP: Component> NavigationContextExt for yew::html::Scope<COMP> {
}
fn push_relative_route(&self, path: &str) {
- let path = normalize_segment(path);
- //log::info!("PUSH REL {}", path);
- if let Some((nav_ctx, _handle)) = self.context::<NavigationContext>(Callback::from(|_| {}))
- {
- let abs_path = match &nav_ctx.parent_path {
- Some(parent_path) => format!("{}/{}", parent_path, path),
- None => format!("/{}", path),
- };
- match self.navigator() {
- Some(navigator) => {
- navigator.push(&AnyRoute::new(abs_path));
- }
- None => {
- log::error!("no Navigator found");
- }
- }
- } else {
- match self.navigator() {
- Some(navigator) => {
- let path = format!("/{}", path);
- navigator.push(&AnyRoute::new(path));
- }
- None => {
- log::error!("no Navigator found");
- }
- }
+ let new_path = get_new_absolute_path(self, path);
+ match self.navigator() {
+ Some(navigator) => navigator.push(&AnyRoute::new(new_path)),
+ None => log::error!("no Navigator found"),
+ }
+ }
+
+ fn replace_relative_route(&self, path: &str) {
+ let new_path = get_new_absolute_path(self, path);
+ match self.navigator() {
+ Some(navigator) => navigator.replace(&AnyRoute::new(new_path)),
+ None => log::error!("no Navigator found"),
}
}
}
--
2.47.3
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [yew-devel] [PATCH yew-widget-toolkit 2/2] widget: tab panel: improve route handling on creation
2025-12-16 9:55 [yew-devel] [PATCH yew-widget-toolkit 1/2] state: navigation: add 'replace_relative_route' to NavigationContextExt Dominik Csapak
@ 2025-12-16 9:55 ` Dominik Csapak
2025-12-16 10:35 ` [yew-devel] applied: " Dietmar Maurer
2025-12-16 10:35 ` [yew-devel] applied: [PATCH yew-widget-toolkit 1/2] state: navigation: add 'replace_relative_route' to NavigationContextExt Dietmar Maurer
1 sibling, 1 reply; 4+ messages in thread
From: Dominik Csapak @ 2025-12-16 9:55 UTC (permalink / raw)
To: yew-devel
instead of always pushing the route, replace the route, and only if the
selected tab is not the default one.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
src/widget/tab/tab_bar.rs | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/src/widget/tab/tab_bar.rs b/src/widget/tab/tab_bar.rs
index d307ca0..d3de24f 100644
--- a/src/widget/tab/tab_bar.rs
+++ b/src/widget/tab/tab_bar.rs
@@ -264,8 +264,10 @@ impl Component for PwtTabBar {
if !(active.is_some() && (path.is_empty() || path == "_")) {
active = get_active_or_default(props, &Some(Key::from(path)));
- } else if let Some(active) = active.as_deref() {
- ctx.link().push_relative_route(active);
+ } else if active != props.get_default_active() {
+ if let Some(active) = active.as_deref() {
+ ctx.link().replace_relative_route(active);
+ }
}
}
}
--
2.47.3
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [yew-devel] applied: [PATCH yew-widget-toolkit 1/2] state: navigation: add 'replace_relative_route' to NavigationContextExt
2025-12-16 9:55 [yew-devel] [PATCH yew-widget-toolkit 1/2] state: navigation: add 'replace_relative_route' to NavigationContextExt Dominik Csapak
2025-12-16 9:55 ` [yew-devel] [PATCH yew-widget-toolkit 2/2] widget: tab panel: improve route handling on creation Dominik Csapak
@ 2025-12-16 10:35 ` Dietmar Maurer
1 sibling, 0 replies; 4+ messages in thread
From: Dietmar Maurer @ 2025-12-16 10:35 UTC (permalink / raw)
To: Yew framework devel list at Proxmox, Dominik Csapak
applied
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [yew-devel] applied: [PATCH yew-widget-toolkit 2/2] widget: tab panel: improve route handling on creation
2025-12-16 9:55 ` [yew-devel] [PATCH yew-widget-toolkit 2/2] widget: tab panel: improve route handling on creation Dominik Csapak
@ 2025-12-16 10:35 ` Dietmar Maurer
0 siblings, 0 replies; 4+ messages in thread
From: Dietmar Maurer @ 2025-12-16 10:35 UTC (permalink / raw)
To: Yew framework devel list at Proxmox, Dominik Csapak
applied
_______________________________________________
yew-devel mailing list
yew-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/yew-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-16 10:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-16 9:55 [yew-devel] [PATCH yew-widget-toolkit 1/2] state: navigation: add 'replace_relative_route' to NavigationContextExt Dominik Csapak
2025-12-16 9:55 ` [yew-devel] [PATCH yew-widget-toolkit 2/2] widget: tab panel: improve route handling on creation Dominik Csapak
2025-12-16 10:35 ` [yew-devel] applied: " Dietmar Maurer
2025-12-16 10:35 ` [yew-devel] applied: [PATCH yew-widget-toolkit 1/2] state: navigation: add 'replace_relative_route' to NavigationContextExt Dietmar Maurer
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.