for the NavMenu to re-render, you need to trigger a state change for the component. your code could update one of its properties, or your nav component could register an event handler for authentication state change, and then trigger a state change for the component when the authentication state changes.
Dynamic NavMenu
Onyango, David
31
Reputation points
I am trying to implement the default NavMenu.razor with a number of NavLinks where one of the items is not visible by default. It should only become visible after an authenticated user belonging to a specific role condition is true. My code snippet is below. It seems a challenge of refreshing the navmenu. I have attempted implementing StateHasChanged() at various points without success. Kindly advise.
@if (authService.isinTargetRole)
{
<NavLink class="nav-link" href="targetPage")>
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Target Page
</NavLink>
} else
{
<NavLink class="nav-link" href="targetPage" hidden>
<span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Target Page
</NavLink>
}
Developer technologies .NET .NET MAUI
4,152 questions
1 answer
Sort by: Most helpful
-
Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
2025-06-21T18:18:33.9433333+00:00