[英]Blazor server app.razor get route parameter
I wrap my app with a custom provider in App.Razor (MyApiProvider).我用 App.Razor (MyApiProvider) 中的自定义提供程序包装我的应用程序。
Is it possible to extract a route parameter in the App.razor page or is it too early in the app lifecycle?是否可以在 App.razor 页面中提取路由参数,还是在应用生命周期中为时过早? I want to get an ID and then send through to MyApiProvider as the TestParameter.
我想获取一个 ID,然后作为 TestParameter 发送给 MyApiProvider。
<MyApiProvider TestParameter="Hello">
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, theres nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</MyApiProvider>
@code {
//Route data?
}
You can add the OnNavigationAsync as shown in this example to capture the route at the app level:您可以添加 OnNavigationAsync 如此示例所示,以在应用程序级别捕获路由:
https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-5.0#route-to-components-from-multiple-assemblies https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-5.0#route-to-components-from-multiple-assemblies
It only provides you the path (but I guess that's all you need if it is a simple Get request)它只为您提供路径(但我想如果它是一个简单的 Get 请求,这就是您所需要的全部)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.