为了在 BlazorWebAssembly 中更改默认页面,可以在 App
组件中添加一个 @page
指令并指定新的默认页面路径。例如,如果想将默认页面更改为 MyPage
,可以将 App
组件中的 @page "/"
指令改为 @page "/MyPage"
。以下是代码示例:
@using Microsoft.AspNetCore.Components.WebAssembly.Hosting
@using Microsoft.Extensions.DependencyInjection
@using MyApp
Sorry, there's nothing at this address.
@code {
[Obsolete("This class is obsolete.")]
public partial class App : ComponentBase
{
protected override void OnInitialized()
{
NavigationManager.NavigateTo("/MyPage");
}
}
}