Multiple App.Razor components

Kuler Master 386 Reputation points
2025-01-31T08:47:54.43+00:00

Hello,

Is it possible to have an additional App.razor file that I can use for e.g. Admin area only?

Currently, if I create a new folder named Admin and create a new layout there, it inherits from the existing App.razor and linked css files.

Basically, I need to have separate css files in the admin area.

Thank you!

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,767 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,656 questions
ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,586 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 70,376 Reputation points
    2025-01-31T16:47:33.2266667+00:00

    Blazor use a single component tree. The app component is the root node, of which there can only be one. As for css, there is only one browser instance, so css by definition is shared with all components. Blazor components support “isolation” css by prefixing all class references with a unique selector.

    https://learn.microsoft.com/en-us/aspnet/core/blazor/components/css-isolation?view=aspnetcore-9.0

    I assume you want admin to look like a new page. In that case the admin pages should reference their own layout.

    https://learn.microsoft.com/en-us/aspnet/core/blazor/components/layouts?view=aspnetcore-9.0#apply-a-default-layout-to-an-app

    0 comments No comments

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.