Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Blazor component routing for dynamic pages

I came up with a strange task.

I have 3 Blazor components with dynamic pages, and do not understand how I can release it.

Q: How can I can reduce the number of lines @page "/"... @page "/...{section}"

Or maybe who know how I can exclude some urls like @PageExlude "..."

[HomePage.razor]

@page "/"
@page "/{section1}"
@page "/{section1}/{section2}"
...
@page "/{section1}/{section2}/.../{sectionX}"

.... CODE ....

[AdminPage.razor]

@page "/admin/"
@page "/admin/{section1}"
@page "/admin/{section1}/{section2}"
@page "/admin/{section1}/{section2}/{section3}"
@page "/admin/{section1}/{section2}/{section3}/{section4}"

.... CODE ....

[PreviewPageContent.razor]

@page "/admin/previewPage/{PageId:int}"
@page "/admin/previewPage/{PageId:int}/{Revision:int}"

.... CODE ....

for people who do not understand the task:

when I call -> Result
localhost/ -> HomePage.razor
localhost/admin/ -> HomePage.razor
localhost/previewPage/1 -> HomePage.razor
localhost/Identity/Account/Manage/Index -> HomePage.razor
like image 365
TDG Avatar asked Dec 20 '25 04:12

TDG


1 Answers

Catch-all route parameters are another way to handle this. https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-6.0 enter image description here

like image 148
William Gilmore Avatar answered Dec 21 '25 18:12

William Gilmore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!