Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blazor Catch-All Route ignores razor page routes #42584

Closed
1 task done
tbasallo opened this issue Jul 5, 2022 · 3 comments
Closed
1 task done

Blazor Catch-All Route ignores razor page routes #42584

tbasallo opened this issue Jul 5, 2022 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-server ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved

Comments

@tbasallo
Copy link

tbasallo commented Jul 5, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When a catch-all route is included (using @page "/{*params)") routing for Razor pages is ignored and the catch-all intercepts routes and never loads the razor pages.

Conversely, if a Razor page catch-all is included, Blazor outing is ignored.

Expected Behavior

All routes should be checked and then when no routes match (Blazor or Razor) then the catch-all applies.

Steps To Reproduce

Create a project with both Blazor and Razor pages.
Add a page for each (Blazor and Razor)
Add a Blazor catch-all route
Try to open the Razor page, the Blazor catch-all intercepts

Exceptions (if any)

No response

.NET Version

ASP.NET 6

Anything else?

Endpoint routing:

app.MapControllers();
app.MapRazorPages();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
@mkArtakMSFT mkArtakMSFT added area-blazor Includes: Blazor, Razor Components feature-blazor-server labels Jul 5, 2022
@javiercn
Copy link
Member

javiercn commented Jul 6, 2022

@tbasallo thanks for contacting us.

Unfortunately, that is not how routing works.

MapFallbackToPage adds a catch-all route with the lowest possible order, if you add a similar catchall route to a razor page, then that catchall will match because it has a higher order.

This is not something we plan to change in the near future. We have a separate item to more correctly understand Blazor routes as described here

The best approach you could take would be to use dynamic routing to make a selection of which endpoint to match on a per request basis. Check https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.routing.dynamicroutevaluetransformer?view=aspnetcore-6.0 for details.

@javiercn javiercn added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Jul 6, 2022
@ghost ghost added the Status: Resolved label Jul 6, 2022
@tbasallo
Copy link
Author

tbasallo commented Jul 6, 2022

@javiercn thanks for the quick response.

I ended up adding a component into the Blazor NotFound element that does exactly what a page would have done (check CMS or return 404 content). Seems to be working.

@ghost
Copy link

ghost commented Jul 7, 2022

This issue has been resolved and has not had any activity for 1 day. It will be closed for housekeeping purposes.

See our Issue Management Policies for more information.

@ghost ghost closed this as completed Jul 7, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 6, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-blazor Includes: Blazor, Razor Components feature-blazor-server ✔️ Resolution: Duplicate Resolved as a duplicate of another issue Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants