Repository: dotnet/aspnetcore
File: src/Components/Endpoints/src/DependencyInjection/HttpNavigationManager.cs (C#)

Code before:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Components.Routing;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.AspNetCore.Components.Endpoints;

internal sealed class HttpNavigationManager : NavigationManager, IHostEnvironmentNavigationManager
{
    private const string _disableThrowNavigationException = "Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException";

    [FeatureSwitchDefinition(_disableThrowNavigationException)]
    private static bool _throwNavigationException =>
        !AppContext.TryGetSwitch(_disableThrowNavigationException, out var switchValue) && switchValue;

    private Func<string, Task>? _onNavigateTo;

    void IHostEnvironmentNavigationManager.Initialize(string baseUri, string uri) => Initialize(baseUri, uri);

    void IHostEnvironmentNavigationManager.Initialize(string baseUri, string uri, Func<string, Task> onNavigateTo)
    {
        _onNavigateTo = onNavigateTo;
        Initialize(baseUri, uri);
    }

    protected override void NavigateToCore(string uri, NavigationOptions options)
    {
        var absoluteUriString = ToAbsoluteUri(uri).AbsoluteUri;
        if (_throwNavigationException)
        {
            throw new NavigationException(absoluteUriString);
        }
        else
        {
            _ = PerformNavigationAsync();
        }

        async Task PerformNavigationAsync()
        {

Review comment (suggestion):
The new condition for _throwNavigationException will always yield false when the switch is not set. Changing the logic to use an OR operator (e.g. !AppContext.TryGetSwitch(_disableThrowNavigationException, out var switchValue) || !switchValue) should ensure that by default, with no switch set or with a false value, exception throwing is enabled.
```suggestion
        !AppContext.TryGetSwitch(_disableThrowNavigationException, out var switchValue) || !switchValue;
```

Code after:
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Components.Routing;
using System.Diagnostics.CodeAnalysis;

namespace Microsoft.AspNetCore.Components.Endpoints;

internal sealed class HttpNavigationManager : NavigationManager, IHostEnvironmentNavigationManager
{
    private const string _disableThrowNavigationException = "Microsoft.AspNetCore.Components.Endpoints.NavigationManager.DisableThrowNavigationException";

    [FeatureSwitchDefinition(_disableThrowNavigationException)]
    private static bool _throwNavigationException =>
        !AppContext.TryGetSwitch(_disableThrowNavigationException, out var switchValue) || !switchValue;

    private Func<string, Task>? _onNavigateTo;

    void IHostEnvironmentNavigationManager.Initialize(string baseUri, string uri) => Initialize(baseUri, uri);

    void IHostEnvironmentNavigationManager.Initialize(string baseUri, string uri, Func<string, Task> onNavigateTo)
    {
        _onNavigateTo = onNavigateTo;
        Initialize(baseUri, uri);
    }

    protected override void NavigateToCore(string uri, NavigationOptions options)
    {
        var absoluteUriString = ToAbsoluteUri(uri).AbsoluteUri;
        if (_throwNavigationException)
        {
            throw new NavigationException(absoluteUriString);
        }
        else
        {
            _ = PerformNavigationAsync();
        }

        async Task PerformNavigationAsync()
        {