{"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/3600ca084e9c8b5f4174fc5e747f4c52d2100806/src/Components/Components/src/NavigationManager.cs#L158-L194","documentation":"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.","triggerScenarios":"NavigationManager.NavigateTo(\"https://example.com/page\", new NavigationOptions { RelativeToCurrentUri = true }) or any absolute URI when the option is set.","commonSituations":"Constructing URIs dynamically without checking if they are absolute, mixing relative and absolute handling, or defaulting RelativeToCurrentUri to true and passing full URLs.","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."],"exampleFix":"// before\nNavigationManager.NavigateTo(\"https://app.com/section/page\", new NavigationOptions { RelativeToCurrentUri = true });\n// after\nNavigationManager.NavigateTo(\"section/page\", new NavigationOptions { RelativeToCurrentUri = true });","handlingStrategy":"validation","validationCode":"// Only set RelativeToCurrentUri for genuinely relative URIs.\nvar opts = new NavigationOptions { RelativeToCurrentUri = !IsAbsoluteUri(uri) };\nNavigationManager.NavigateTo(uri, opts);","typeGuard":"static bool IsAbsoluteUri(string uri) => Uri.IsWellFormedUriString(uri, UriKind.Absolute);","tryCatchPattern":null,"preventionTips":["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."],"tags":["blazor","navigation","uri","navigation-manager"],"backgroundTag":null,"analyzedSha":"3600ca084e9c8b5f4174fc5e747f4c52d2100806","analyzedAt":"2026-08-11T16:32:30.678Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}