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

Static files can't be served from the root when a Razor page component matches that route with param #52320

Closed
1 task done
marinasundstrom opened this issue Nov 23, 2023 · 3 comments
Labels
area-blazor Includes: Blazor, Razor Components ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved

Comments

@marinasundstrom
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

TL;DR; Static files can't be served from the root when a Razor page component matches that route.

Consider that you are building a CMS. You have Page component that is supposed to display page content, so you want to catch the "permalink" like so:

@page "/{permalink}"

That is all fine so far. The component gets hit upon navigating to: http://localhost:5000/this-is-a-test.

The problem with this path seems to have precedence over static file. So it catches all routes and paths, including static files.

Because of this static files can't be served from the root.

Describe the solution you'd like

Guidance in how to solve such a situation. Since I imagine this is a common case for larger sites to want to use not only simple parameters, but also for wildcards.

As a solution in my case, I guess that I could put resources in sub-folders in the wwwroot-folder. That would work in this instance, but not for wildcards params.

Additional context

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-blazor Includes: Blazor, Razor Components label Nov 23, 2023
@marinasundstrom marinasundstrom changed the title Wildcard route for component page Static files can't be served from the root when a Razor page component matches that route Nov 23, 2023
@marinasundstrom marinasundstrom changed the title Static files can't be served from the root when a Razor page component matches that route Static files can't be served from the root when a Razor page component matches that route with param Nov 23, 2023
@javiercn
Copy link
Member

@marinasundstrom thanks for contacting us.

This is by design; the route is capturing any path with one segment. The same behavior happens on Razor pages or controllers, it didn't happen in old Blazor Server because there was a catch-all route with. There's a :nonfile constraint for it.

The reason this didn't happen in previous versions of Blazor is because MapFallback* use a route {**path:nonfile} in their default overloads

@javiercn javiercn added question ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. labels Nov 23, 2023
@ghost ghost added the Status: Resolved label Nov 23, 2023
@marinasundstrom
Copy link
Author

@javiercn OK. Good to know! I will try the constraint.

Thank you so much!

@ghost
Copy link

ghost commented Nov 24, 2023

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 Nov 24, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Feb 7, 2024
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 ✔️ Resolution: Answered Resolved because the question asked by the original author has been answered. question Status: Resolved
Projects
None yet
Development

No branches or pull requests

2 participants