Blazor WASM中使用URL路由非常方便,可以使用Blazor提供的Routing模块来实现。下面是一个示例:
1.添加依赖包 Microsoft.AspNetCore.Components.WebAssembly.Routing
dotnet add package Microsoft.AspNetCore.Components.WebAssembly.Routing
2.将以下内容添加到App.razor文件中以启用路由:
Sorry, there's nothing at this address.
3.在页面上使用Route标记来定义路由路径和组件:
@page "/"
Welcome to the home page!
@page "/about"
Welcome to the about page!
以上就是使用Blazor WASM进行URL路由的基本示例。