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

  1. Pass a relative URI (e.g. 'page', 'folder/page', '../other') when RelativeToCurrentUri is true.
  2. Set RelativeToCurrentUri = false for absolute URIs.
  3. 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

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


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)