作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在预览版 8 中创建了一个新的 Blazor 服务器端应用程序。当我调用 UriHelper.NavigateTo 从 Index.razor 页面转到计数器页面时,计数器页面被调用两次。
在 Index.razor 页面中,我有以下代码:
@code{
protected async override Task OnInitializedAsync()
{
UriHelper.NavigateTo("/counter");
}
}
protected override void OnInitialized()
{
}
最佳答案
这种行为是因为预渲染功能。请注意,当您在 counter page
上时(加载两次),如果您点击 Home
,只有一个执行被触发:
总结:
启用预渲染时(默认情况下),预渲染页面的 OnInitializedAsync
被调用两次 by design .因此,您的重定向语句会执行两次。
测试是我在索引 OnInitializedAsync
上写了这段代码:
@page "/"
@inject IUriHelper UriHelper
<h1>Hello, world!</h1>
Welcome to your new app.
@code{
protected async override Task OnInitializedAsync()
{
System.Console.WriteLine("_* ");
System.Console.WriteLine("_**************************");
System.Console.WriteLine("_***** Pre render ******");
System.Console.WriteLine("_**************************");
System.Console.WriteLine("_ ");
return;
}
}
OnInitializedAsync
执行两次:
关于Blazor UriHelper.NavigateTo 两次调用页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57680784/
我在预览版 8 中创建了一个新的 Blazor 服务器端应用程序。当我调用 UriHelper.NavigateTo 从 Index.razor 页面转到计数器页面时,计数器页面被调用两次。 在 In
var displayUrl = UriHelper.GetDisplayUrl(Request); var urlBuilder = new UriBuilder(displayUrl) { Qu
我是 .NET 框架的新手,我遇到了 Microsoft.AspNetCore.Http.HttpRequest 接口(interface)的问题。我正在尝试使用 GetDisplayUri扩展名,但
我是一名优秀的程序员,十分优秀!