Language

NavigationManagerExtensions.GetUriWithFragment Method

Definition

Returns a URI constructed from Uri with a fragment added, updated, or removed.

public static string GetUriWithFragment(this Microsoft.AspNetCore.Components.NavigationManager navigationManager, string? fragment);
static member GetUriWithFragment : Microsoft.AspNetCore.Components.NavigationManager * string -> string
<Extension()>
Public Function GetUriWithFragment (navigationManager As NavigationManager, fragment As String) As String

Parameters

navigationManager
NavigationManager

The NavigationManager.

fragment
String

The fragment string. If null or empty, the fragment will be removed from the URI.

Returns

The URI with the specified fragment.

Remarks

If fragment does not start with #, then # will be prepended.

This method is useful when the document's baseURI differs from its location, such as when a <base> element is used, since relative hash URLs are resolved relative to the baseURI.

@inject NavigationManager Nav
<a href="@Nav.GetUriWithFragment("section1")">Go to section 1</a>

Applies to