HOWTO: Add Dynamic Routing in Blazor

Matthew Holton 331 Reputation points
2021-11-02T17:13:35.473+00:00

Hello,

I am looking to add dynamic routing to my Blazor server app, is this possible? Will it be possible in 6.0?

To be more clear, I have a page component (Browse.razor) that I will use to list results in a grid. When a user navigates to either /accounts or /orders, I would like this component used. I know I can do this with the @Anonymous directive, but I would like to configure this in configuration so that I may configure other uri's for this. In other words, I would like to have a completely configurable navigation that reuses a common component (Grid or Form).

I am looking to port an existing application bit by bit over to Blazor. My BA's understand the application well enough that if I were to provide them the application shell and framework to configure the navigation, API calls, validation rules and layout templates - they would then be able to reconstitute a new rendition of the existing application as a Blazor one.

It seems to me that while routes is just a collection, the @Anonymous directive is required since Blazor generates composite code during the build process. There doesn't see to be a way to assign additional routes on a page post deployment.

For now, I can use "/{area:string}/browse/{view: string}/{filters:string}" or "/{area:string}/edit/{formname: string}/{parameters:string}" for the uri and go from there. I was just wondering if there was a mechanism to add these patterns post build.

Thanks

Developer technologies .NET Blazor
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce Barker 801 Reputation points
    2021-11-02T20:07:41.047+00:00

    I'm not sure your immediate goal. It appears you want your site to part blazor and part razor.

    see:

    https://www.meziantou.net/integrating-blazor-components-into-razor-pages-and-mvc-apps.htm


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.