-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: [FluentNavLink] An issue where empty strings were not allowed in Href #2722
Conversation
There is a reason we do not want to have empty Hrefs. This is done on purpose so you can have entries in the FluentNavMenu that don't necessarily go somewhere but do invoke an action. Like in the https://www.fluentui-blazor.net/NavMenu#navigation-examples:
If you still need to have a link that goes to the homepage, you can use asa value either See also #1654 |
The original NavLink component accepts an empty string, and the link below recommends an empty string as a way to navigate to the root page. Example <div class="nav-scrollable"
onclick="document.querySelector('.navbar-toggler').click()">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="" Match="NavLinkMatch.All">
<span class="bi bi-house-door-fill-nav-menu"
aria-hidden="true"></span> Home
</NavLink>
</div>
+ @foreach (var name in GetRoutableComponents())
+ {
+ <div class="nav-item px-3">
+ <NavLink class="nav-link"
+ href="@Regex.Replace(name, @"(\B[A-Z]|\d+)", "-$1").ToLower()">
+ @Regex.Replace(name, @"(\B[A-Z]|\d+)", " $1")
+ </NavLink>
+ </div>
+ }
</nav>
</div> |
Since that property is nullable, it will work as intended, as long as you don't make the mistake of declaring the Href to be an empty string and throwing in an OnClick callback. |
Tested on the |
Pull Request
π Description
Fixed FluentNavLink not working correctly when Href was empty
π©βπ» Reviewer Notes
So simple PR
π Test Plan
Verify that clicking on a FluentNavLink correctly navigates to the root page when the Href of the FluentNavLink is empty.
β Checklist
General
Component-specific