VinceB
VinceB

Reputation: 1

How to disable the NavMenu in Blazor?

I use the default Blazor NavMenu component and want to disable it when the user opens a window. In my app the input data from the user on the opened page has to be validated first before the user is allowed to click another item on the NavMenu.

Upvotes: 0

Views: 22

Answers (1)

MrC aka Shaun Curtis
MrC aka Shaun Curtis

Reputation: 30310

Wrap the links you only want shown when authorized in AuthorizeView.

Here's a demo:

<AuthorizeView>
    <Authorized>
        <p>Hello, @context.User.Identity?.Name!</p>
        <p><button @onclick="HandleClick">Authorized Only Button</button></p>
    </Authorized>
    <NotAuthorized>
        <p>You're not authorized.</p>
    </NotAuthorized>
</AuthorizeView>

The Microsoft Docs article is here: https://learn.microsoft.com/en-us/aspnet/core/blazor/security/?view=aspnetcore-9.0&tabs=visual-studio#authorizeview-component

Upvotes: 1

Related Questions