This code will help you to understand how to get the current URL in a Blazor component.
How do you get the current URL in a Blazor component?Inject NavigationManager in razor.
@inject NavigationManager NavigationManager
Use Uri from NavigationManager to get the current URL.
string currentUrl = NavigationManager.Uri;
sample code:
@page "/sample" @inject NavigationManager NavigationManager <p>@currentUrl</p> @code { private string currentUrl; protected override void OnInitialized() { currentUrl = NavigationManager.Uri; } }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
How do you get the current URL in a Blazor component?
Inject NavigationManager in razor.
Use Uri from NavigationManager to get the current URL.
sample code:
need an explanation for this answer? contact us directly to get an explanation for this answer