diff --git a/packages/router/src/components/link.rs b/packages/router/src/components/link.rs index 067895f11..cea1cb3bf 100644 --- a/packages/router/src/components/link.rs +++ b/packages/router/src/components/link.rs @@ -195,7 +195,7 @@ impl Debug for LinkProps { /// # vdom.rebuild_in_place(); /// # assert_eq!( /// # dioxus_ssr::render(&vdom), -/// # r#"A fully configured link"# +/// # r#"A fully configured link"# /// # ); /// ``` #[allow(non_snake_case)] @@ -252,6 +252,8 @@ pub fn Link(props: LinkProps) -> Element { Some(class_) }; + let aria_current = (href == current_url).then_some("page"); + let tag_target = new_tab.then_some("_blank"); let is_external = matches!(parsed_route, NavigationTarget::External(_)); @@ -286,6 +288,7 @@ pub fn Link(props: LinkProps) -> Element { class, rel, target: tag_target, + aria_current, ..attributes, {children} } diff --git a/packages/router/tests/via_ssr/link.rs b/packages/router/tests/via_ssr/link.rs index 66b76c7c4..9c5246dcc 100644 --- a/packages/router/tests/via_ssr/link.rs +++ b/packages/router/tests/via_ssr/link.rs @@ -173,10 +173,11 @@ fn with_active_class_active() { } let expected = format!( - "

App

Link", + "

App

Link", href = r#"href="/""#, default = r#"dioxus-prevent-default="onclick""#, class = r#"class="test_class active_class""#, + aria = r#"aria-current="page""#, ); assert_eq!(prepare::(), expected);