pub struct NavLinkProps {
pub href: String,
pub active: bool,
pub disabled: bool,
pub prevent_default: bool,
pub onclick: Option<EventHandler<MouseEvent>>,
pub class: String,
pub children: Element,
/* private fields */
}Expand description
Bootstrap NavLink component.
§Bootstrap HTML → Dioxus
| HTML | Dioxus |
|---|---|
<a class="nav-link active" href="/">Home</a> | NavLink { href: "/", active: true, "Home" } |
<a class="nav-link disabled" aria-disabled="true" tabindex="-1">Disabled</a> | NavLink { disabled: true, "Disabled" } |
For single-page apps that switch content client-side, set prevent_default: true
so a click on a #-href link runs only your onclick handler and does not
follow the anchor (no hash change, no scroll-to-top). For a JS-toggled tab
button (<button class="nav-link">) use NavButton instead of an anchor.
rsx! {
NavLink { href: "/dashboard", active: true, "Dashboard" }
// SPA tab link: handler runs, page does not navigate.
NavLink { prevent_default: true, onclick: move |_| { /* switch section */ }, "Settings" }
}Fields§
§href: StringLink href.
active: boolActive state.
disabled: boolDisabled state.
prevent_default: boolCall event.prevent_default() on click so the anchor is not followed
(SPA-safe: the onclick handler runs, but the URL/hash is untouched and
the page does not scroll to top). Matches what Bootstrap’s own JS does
for #-href toggle links.
onclick: Option<EventHandler<MouseEvent>>Click event handler.
class: StringAdditional CSS classes.
children: ElementChild elements.
Implementations§
Sourcepub fn builder() -> NavLinkPropsBuilder<((), (), (), (), (), (), (), ())>
pub fn builder() -> NavLinkPropsBuilder<((), (), (), (), (), (), (), ())>
Create a builder for building NavLinkProps.
On the builder, call .href(...)(optional), .active(...)(optional), .disabled(...)(optional), .prevent_default(...)(optional), .onclick(...)(optional), .class(...)(optional), .attributes(...)(optional), .children(...)(optional) to set the values of the fields.
Finally, call .build() to create the instance of NavLinkProps.
Trait Implementations§
Source§fn clone(&self) -> NavLinkProps
fn clone(&self) -> NavLinkProps
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more