Skip to content

Active class if target URL/route is within the current URL #1946

Closed Answered by tirithen
tirithen asked this question in Q&A
Discussion options

You must be logged in to vote

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?

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(&current_route) { "button…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tirithen
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant