{"record":{"id":"102404ee7185d0d4","repo":"PrismLibrary/Prism","slug":"the-constructed-uri-contains-one-or-more-relative-back","errorCode":null,"errorMessage":"The constructed URI contains one or more relative back operators, but contains no other navigation segments - '{uri}'.","messagePattern":"The constructed URI contains one or more relative back operators, but contains no other navigation segments - '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilder.cs","lineNumber":113,"sourceCode":"        foreach ((var key, var value) in parameters)\n            _navigationParameters.Add(key, value);\n\n        return this;\n    }\n\n    internal Uri BuildUri()\n    {\n        var uri = (_absoluteNavigation ? \"/\" : string.Empty) +\n            string.Join(\"/\", _uriSegments.Select(x => x.Segment));\n\n        if(uri.Contains(\"../\"))\n        {\n            if (_absoluteNavigation)\n                throw new InvalidOperationException(\"The generated URI has one or more relative back operators and was marked as an absolute path. This is not supported.\");\n\n            var segments = uri.Split('/');\n            if (!segments.Any(x => x != \"..\"))\n                throw new InvalidOperationException($\"The constructed URI contains one or more relative back operators, but contains no other navigation segments - '{uri}'.\");\n            var hasNonBackSegment = false;\n            for(int i = 0; i < segments.Length; i++)\n            {\n                if (hasNonBackSegment && segments[i] == \"..\")\n                    throw new InvalidOperationException($\"The constructed URI has a relative back operator after a new Navigation Segment which is not supported - '{uri}'.\");\n                else if (segments[i] != \"..\")\n                    hasNonBackSegment = true;\n            }\n        }\n\n        return UriParsingHelper.Parse(uri);\n    }\n}\n","sourceCodeStart":95,"sourceCodeEnd":127,"githubUrl":"https://github.com/PrismLibrary/Prism/blob/358118cd640d9a22ff8cf21c8ad197fa038b7990/src/Maui/Prism.Maui/Navigation/Builder/NavigationBuilder.cs#L95-L127","documentation":"BuildUri validates relative URIs containing '..' segments: if every segment is a back operator and there is nothing to navigate back to a sibling of, the constructed URI is meaningless. Prism throws InvalidOperationException including the offending URI so the developer can see what was built.","triggerScenarios":"Chaining only RelativeBack() calls (or AddSegment(\"..\") repeatedly) with no real page segments, then calling NavigateAsync() or Uri — e.g. builder.RelativeBack().RelativeBack().NavigateAsync().","commonSituations":"Over-estimating how many back steps are available; building the URI programmatically in a loop that emits only '..' segments; calling RelativeBack on a fresh builder with no preceding page segment.","solutions":["Ensure at least one non-back segment exists: start with a page segment before/after RelativeBack(), e.g. RelativeBack().AddSegment(\"OtherPage\").","Count available navigation stack depth before emitting back operators and cap the number of '..' segments.","If the goal is simply going back in the stack, use INavigationService.GoBackAsync() instead of building a '..'-only URI."],"exampleFix":"// before\nnavigationService.CreateBuilder().RelativeBack().RelativeBack().NavigateAsync(); // only back segments\n// after\nnavigationService.CreateBuilder().RelativeBack().AddSegment(\"DetailPage\").NavigateAsync();","handlingStrategy":"validation","validationCode":"var segs = new[] { \"..\", \"..\" }; // whatever you built\nif (segs.All(s => s == \"..\"))\n    throw new InvalidOperationException(\"A relative-back URI must include at least one real page segment; use GoBackAsync() instead.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    await navigationService.NavigateAsync(uri);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"no other navigation segments\"))\n{\n    await navigationService.GoBackAsync();\n}","preventionTips":["Use GoBackAsync() when the intent is simply popping the navigation stack.","Cap the number of RelativeBack() calls to the number of segments you previously navigated through.","Keep navigation chains as named flows in helpers instead of ad-hoc segment strings."],"tags":["navigation","uri","relative-back"],"backgroundTag":"invalid-url-format","analyzedSha":"358118cd640d9a22ff8cf21c8ad197fa038b7990","analyzedAt":"2026-09-15T15:00:31.079Z","contentChangedAt":"2026-09-15T15:00:31.079Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}