admin管理员组文章数量:1122832
I have a page with an OnInitialized() method. In that method, I set some cookies and get information from the database include a route to redirect to. I then try to use the NavigationManager's NavigateTo() method to navigate to that URL, but Visual Studio throws an error with not much info.
Message "Exception of type 'Microsoft.AspNetCore.Components.NavigationException' was thrown." string
Visual Studio allows me to continue and the app will redirect, if it is not the same as the current URL, but my Login component is not updated. I have to refresh the page manually to see the page as it should be.
This behavior seems odd. Why do I get the exception? And why is the other component not refreshed after changing locations?
I have a page with an OnInitialized() method. In that method, I set some cookies and get information from the database include a route to redirect to. I then try to use the NavigationManager's NavigateTo() method to navigate to that URL, but Visual Studio throws an error with not much info.
Message "Exception of type 'Microsoft.AspNetCore.Components.NavigationException' was thrown." string
Visual Studio allows me to continue and the app will redirect, if it is not the same as the current URL, but my Login component is not updated. I have to refresh the page manually to see the page as it should be.
This behavior seems odd. Why do I get the exception? And why is the other component not refreshed after changing locations?
Share Improve this question edited Dec 2, 2024 at 6:51 Zhi Lv 21.2k1 gold badge26 silver badges36 bronze badges asked Nov 22, 2024 at 21:38 esr124esr124 514 bronze badges1 Answer
Reset to default 0This is a known issue with SSR, the proposed solution is to set your IDE to ignore this specific exception.
https://github.com/dotnet/aspnetcore/issues/53996
Someone has suggested the following workaround:
public static class BlazorSsrRedirectManagerExtensions
{
public static void RedirectTo(this HttpContext httpContext, string redirectionUrl)
{
ArgumentNullException.ThrowIfNull(httpContext);
httpContext.Response.Headers.Append("blazor-enhanced-nav-redirect-location", redirectionUrl);
httpContext.Response.StatusCode = 200;
}
}
add this to the calling page:
@code{
[CascadingParameter] public HttpContext? HttpContext { get; set; }
}
本文标签: Issue redirecting with NavigationManager in OnInitialized method for Blazor appStack Overflow
版权声明:本文标题:Issue redirecting with NavigationManager in OnInitialized method for Blazor app - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736300668a1930899.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论