{"record":{"id":"b7b5d4c18e155f5b","repo":"dotnet/aspnetcore","slug":"the-uri-relativeuri-is-not-a-relative-uri-whe","errorCode":null,"errorMessage":"The URI '{relativeUri}' is not a relative URI. When RelativeToCurrentUri is true, the URI must be relative (e.g., 'page.html', 'folder/page', '../other').","messagePattern":"The URI '(.+?)' is not a relative URI\\. When RelativeToCurrentUri is true, the URI must be relative \\(e\\.g\\., 'page\\.html', 'folder/page', '\\.\\./other'\\)\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Components/Components/src/NavigationManager.cs","lineNumber":176,"sourceCode":"    /// (as returned by <see cref=\"BaseUri\"/>).</param>\n    /// <param name=\"options\">Provides additional <see cref=\"NavigationOptions\"/>.</param>\n    public void NavigateTo([StringSyntax(StringSyntaxAttribute.Uri)] string uri, NavigationOptions options)\n    {\n        AssertInitialized();\n\n        if (options.RelativeToCurrentUri)\n        {\n            uri = ResolveRelativeToCurrentPath(uri);\n        }\n\n        NavigateToCore(uri, options);\n    }\n\n    internal string ResolveRelativeToCurrentPath(string relativeUri)\n    {\n        if (IsAbsoluteUri(relativeUri))\n        {\n            throw new ArgumentException(\n                $\"The URI '{relativeUri}' is not a relative URI. When RelativeToCurrentUri is true, the URI must be relative (e.g., 'page.html', 'folder/page', '../other').\",\n                nameof(relativeUri));\n        }\n\n        var currentUri = _uri!.AsSpan();\n\n        // fragment-only and query-only references are special cases\n        // that resolve against the full current URI\n        if (relativeUri.StartsWith('#'))\n        {\n            var existingFragmentIndex = currentUri.IndexOf('#');\n            if (existingFragmentIndex >= 0)\n            {\n                return string.Concat(currentUri[..existingFragmentIndex], relativeUri.AsSpan());\n            }\n            return string.Concat(_uri, relativeUri);\n        }\n","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/dotnet/aspnetcore/blob/294cab2f9b2e03af6b953820c7ab497c3c8b7ad9/src/Components/Components/src/NavigationManager.cs#L158-L194","documentation":"Thrown by NavigationManager.ResolveRelativeToCurrentPath when NavigationOptions.RelativeToCurrentUri is true but the supplied URI is absolute (starts with '/' or parses as an absolute URI). When RelativeToCurrentUri is set, the framework resolves the path against the current URI, which only makes sense for relative references.","triggerScenarios":"Calling NavigateTo(uri, new NavigationOptions { RelativeToCurrentUri = true }) with a fully-qualified URL like \"https://host/page\"; passing a site-root-relative path like \"/folder/page\" (leading slash counts as absolute); reusing the same URI string for both relative and absolute navigation modes.","commonSituations":"Mixing client-side relative links with absolute URLs generated by a backend; a toggle flag defaulting to true while the code passes absolute URIs; migration from relative to absolute URIs without updating the option.","solutions":["Pass a relative URI (e.g. \"page\", \"sub/page\", \"../other\", \"#frag\", \"?q=1\") when RelativeToCurrentUri is true.","Set RelativeToCurrentUri = false if you must pass an absolute or root-relative URI.","Strip the scheme/host or leading slash before calling when you want path-relative resolution."],"exampleFix":"// before\nnavManager.NavigateTo(\"https://app.com/users/42\", new NavigationOptions { RelativeToCurrentUri = true });\n\n// after\nnavManager.NavigateTo(\"users/42\", new NavigationOptions { RelativeToCurrentUri = true });","handlingStrategy":"validation","validationCode":"static bool IsRelativeForResolution(string uri) =>\n    !uri.StartsWith('/') && !Uri.TryCreate(uri, UriKind.Absolute, out _);\n\nvar opts = new NavigationOptions { RelativeToCurrentUri = true };\nif (opts.RelativeToCurrentUri && !IsRelativeForResolution(uri))\n    throw new ArgumentException(\"URI must be relative when RelativeToCurrentUri is true.\");","typeGuard":null,"tryCatchPattern":"try { navManager.NavigateTo(uri, opts); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"not a relative URI\"))\n{ logger.LogWarning(ex, \"Rejected absolute URI in relative mode\"); }","preventionTips":["Centralize navigation calls behind a helper that validates URI kind vs options.","Default RelativeToCurrentUri to false unless path-relative resolution is explicitly needed.","Log the offending URI at the call site for fast diagnosis."],"tags":["blazor","navigation","uri","configuration"],"analyzedSha":"294cab2f9b2e03af6b953820c7ab497c3c8b7ad9","analyzedAt":"2026-08-06T20:08:02.189Z","schemaVersion":2},"datasetVersion":"2026-08-06T23:17:07.152Z"}