dotnet/aspnetcore · error · ArgumentException
The URI ' ' is not a relative URI. When…
Error message
The URI '{relativeUri}' is not a relative URI. When RelativeToCurrentUri is true, the URI must be relative (e.g., 'page.html', 'folder/page', '../other'). What it means
When NavigationOptions.RelativeToCurrentUri is true, NavigateTo requires a relative URI. Absolute URIs are rejected because the option's contract is to resolve the URI against the current path; an absolute URI would bypass that resolution entirely.
Solutions
- Pass a relative URI (e.g. 'page', 'folder/page', '../other') when RelativeToCurrentUri is true.
- Set RelativeToCurrentUri = false for absolute URIs.
- Strip the base URI prefix before navigating when the option is enabled.
Example fix
// before
NavigationManager.NavigateTo("https://app.com/section/page", new NavigationOptions { RelativeToCurrentUri = true });
// after
NavigationManager.NavigateTo("section/page", new NavigationOptions { RelativeToCurrentUri = true }); Defensive patterns
Strategy: validation
Validate before calling
// Only set RelativeToCurrentUri for genuinely relative URIs.
var opts = new NavigationOptions { RelativeToCurrentUri = !IsAbsoluteUri(uri) };
NavigationManager.NavigateTo(uri, opts); Type guard
static bool IsAbsoluteUri(string uri) => Uri.IsWellFormedUriString(uri, UriKind.Absolute);
Prevention
- Compute RelativeToCurrentUri from whether the URI is absolute.
- Strip the base URI before navigating when the option is enabled.
- Centralize navigation calls in a helper that validates URI kind.
When it happens
Trigger: NavigationManager.NavigateTo("https://example.com/page", new NavigationOptions { RelativeToCurrentUri = true }) or any absolute URI when the option is set.
Common situations: Constructing URIs dynamically without checking if they are absolute, mixing relative and absolute handling, or defaulting RelativeToCurrentUri to true and passing full URLs.
Related errors
- ' ' already initialized.
- The type does not support supplying . To add support, that…
- Cannot format query parameters with values of type
- Cannot have empty query parameter names.
- No enhanced programmatic navigation handler has been…
AI-assisted analysis of dotnet/aspnetcore@3600ca084e (2026-08-11).
Data as JSON: /api/errors/b7b5d4c18e155f5b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Components/Components/src/NavigationManager.cs:176
/// (as returned by <see cref="BaseUri"/>).</param>
/// <param name="options">Provides additional <see cref="NavigationOptions"/>.</param>
public void NavigateTo([StringSyntax(StringSyntaxAttribute.Uri)] string uri, NavigationOptions options)
{
AssertInitialized();
if (options.RelativeToCurrentUri)
{
uri = ResolveRelativeToCurrentPath(uri);
}
NavigateToCore(uri, options);
}
internal string ResolveRelativeToCurrentPath(string relativeUri)
{
if (IsAbsoluteUri(relativeUri))
{
throw new ArgumentException(
$"The URI '{relativeUri}' is not a relative URI. When RelativeToCurrentUri is true, the URI must be relative (e.g., 'page.html', 'folder/page', '../other').",
nameof(relativeUri));
}
var currentUri = _uri!.AsSpan();
// fragment-only and query-only references are special cases
// that resolve against the full current URI
if (relativeUri.StartsWith('#'))
{
var existingFragmentIndex = currentUri.IndexOf('#');
if (existingFragmentIndex >= 0)
{
return string.Concat(currentUri[..existingFragmentIndex], relativeUri.AsSpan());
}
return string.Concat(_uri, relativeUri);
}
View on GitHub (pinned to 3600ca084e)