-
I'm trying to create a navigation component that takes a Vec of routes and renders them. I need an As the routes in some cases will have children I ALSO need the Currently when setting the There was already an issue reported on this here #1241 , and that was closed with a What would be a good way of implementing this functionality in my navigation component with the currently existing API? This is my current navigation component: use dioxus::prelude::*;
use dioxus_router::prelude::*;
#[component]
pub fn Navigation<Route: Routable + PartialEq>(links: Vec<(Route, String)>) -> Element {
rsx! {
nav {
class: "navigation section",
ul {
for link in links {
li {
Link {
class: "button quiet",
active_class: "active",
to: link.0.clone(),
{link.1}
}
}
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I found the way to use It still feels though like a more ergonomic field on the Link component would be a useful addition? use dioxus::prelude::*;
use dioxus_router::prelude::*;
#[component]
pub fn Navigation<Route: Routable + PartialEq>(links: Vec<(Route, String)>) -> Element {
let current_route = use_route::<Route>();
rsx! {
nav {
class: "navigation section",
ul {
for link in links {
li {
Link {
class: if link.0 == current_route || link.0.is_child_of(¤t_route) { "button quiet active" } else { "button quiet" },
to: link.0.clone(),
{link.1}
}
}
}
}
}
}
} |
Beta Was this translation helpful? Give feedback.
I found the way to use
is_child_of
now, I'll put the answer here in case someone else has the same problem.It still feels though like a more ergonomic field on the Link component would be a useful addition?