---
# System prepended metadata

title: '`ASP.NET Core` `NavigationManager.NavigateTo` は、例外を発生させることで画面遷移して要るっぽい 2024-09-16'
tags: [ASP.NET Core, Blazor, NavigationManager.NavigateTo]

---

---
lang: ja-jp
breaks: true
---
# `ASP.NET Core` `NavigationManager.NavigateTo` は、例外を発生させることで画面遷移して要るっぽい 2024-09-16

> NavigationError on NavigateTo
> https://stackoverflow.com/questions/58076758/navigationerror-on-navigateto

> .NET 8 Blazor - NavigationManager.NavigateTo() の一貫性のない動作 #53996
> .NET 8 Blazor - NavigationManager.NavigateTo() Inconsistent Behavior #53996
> https://github.com/dotnet/aspnetcore/issues/53996
> 

## 発生している例外

```=
Exception of type 'Microsoft.AspNetCore.Components.NavigationException' was thrown.
Microsoft.AspNetCore.Components.NavigationException: Exception of type 'Microsoft.AspNetCore.Components.NavigationException' was thrown.
   at Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager.NavigateToCore(String uri, NavigationOptions options)
   at Microsoft.AspNetCore.Components.NavigationManager.NavigateToCore(String uri, Boolean forceLoad)
```

## 画面遷移しない例

```razor=
@inject NavigationManager NavigationManager
・・・
try
{
    NavigationManager.NavigateTo(
        "/Account/GoogleLoginRedirect",
        forceLoad: true
    );
}
catch
{
    // 無視する。
}
```

## 画面遷移する例

```razor=
@inject NavigationManager NavigationManager
・・・
try
{
    NavigationManager.NavigateTo(
        "/Account/GoogleLoginRedirect",
        forceLoad: true
    );
}
catch (Microsoft.AspNetCore.Components.NavigationException ex)
{
    throw;
}

```

###### tags: `ASP.NET Core` `NavigationManager.NavigateTo` `Blazor`
