简体   繁体   中英

Blazor server app.razor get route parameter

I wrap my app with a custom provider in 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? I want to get an ID and then send through to MyApiProvider as the TestParameter.

<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:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM