-
Notifications
You must be signed in to change notification settings - Fork 25.3k
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
Layout namespace for Blazor Web Apps #31170
Comments
🍂🎁 Happy Holidays! ❄️⛄A green dinosaur 🦖 will be along shortly to assist. Stand-by ........ |
Hello @bmeenehan ... Be more specific about the exact layout file location because it shouldn't be required if the layout is discoverable from the Although, it is true that in a Blazor Web App there is an <RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)" /> Whereas for Blazor Server (of yesteryear now), the layouts were in the <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> Let me think about how to address this. I'm now leaning in your direction here. However, I think a blanket statement that will cover all scenarios, including Blazor WASM, makes sense. There's been quite a bit of churn, and trying to version this one is a bit much given that it's a general principle ... you just have to have the namespace available of any object that you intend to use. I guess for the example I should make a Interesting ... the |
Good day Luke,
Thank you for your prompt response.
My custom layout is in the Layout folder, alongside the MainLayout.razor
file. But I got the error "The type or namespace name 'CustomLayout' could
not be found", when adding the @layout directive to a page.
I resolved the error by adding @using [ProjectName].Components.Layout in my
_Imports.razor file.
Is that unexpected behaviour? I'm entirely new to Blazor and still finding
my way around.
…On Thu, 30 Nov 2023 at 13:36, Luke Latham ***@***.***> wrote:
Hello @bmeenehan <https://github.com/bmeenehan> ... Be more specific
about the exact layout file location because it shouldn't be required if
the layout is discoverable from the Layout folder. Blazor finds layouts
in the Layout folder by default.
—
Reply to this email directly, view it on GitHub
<#31170 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADLT7CMCCIMQOEBW222ZHGLYHBVUBAVCNFSM6AAAAABAAULR7WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZTGU4TKOJTGI>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Can you find the layout without using the namespace in your <RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.{CUSTOM LAYOUT})" /> |
I'm going to open a product unit issue on this. I feel like they should've give the |
Yes this did work, and I tried it in the testing process, but I want to
have more than one layout file, and for the MainLayout to remain the
default.
Is there a way to do that in the Routes file, and if so is that best
practice? Adding the @using directive is not a big deal, I simply had to
flail a little to land on that solution.
…On Thu, 30 Nov 2023 at 14:10, Luke Latham ***@***.***> wrote:
Can you find the layout without using the namespace in your _Imports file
by referecing it the same way at the project template with Layout.
supplied ...
<RouteView ***@***.***" ***@***.***(Layout.{CUSTOM LAYOUT})" />
—
Reply to this email directly, view it on GitHub
<#31170 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADLT7CKILQWWFPNX3XG3TSDYHBZTFAVCNFSM6AAAAABAAULR7WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQMZTGY2DOMRTGY>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I opened an issue to ask them about it ☝️. If they say that they'll do it, then I'll try to address this with a general remark at the top of the article saying that the namespace of the layouts wherever they reside must be known and suggest that an WRT your question ... if you just mean setting the layout on a per-component basis, you should be able to just name the layout at the top of a component with ... OR ... You can add an
A layout applied by the |
I'm going to try and fix this now in a somewhat general way. Even if the product unit is willing to add the namespace of the |
Thank you very much |
Description
It is clear how to make a custom layout, using LayoutComponentBase and the @Body directive.
However, it is not mentioned that an @using directive is also required to use the @layout directive on a page.
Page URL
https://learn.microsoft.com/en-us/aspnet/core/blazor/components/layouts?view=aspnetcore-8.0
Content source URL
https://github.com/dotnet/AspNetCore.Docs/blob/main/aspnetcore/blazor/components/layouts.md
Document ID
58e0022a-ac6c-9bf8-380a-40b7d068a887
Article author
@guardrex
The text was updated successfully, but these errors were encountered: