'Add multiple separate templates to the Blazor App Server Side project

I want to add a template for Admin and a template for users and a main site template to the project! I searched a lot but did not find the right training!!!

For the main template, I use the project default and replace the code, but to add the other two templates, how do I create a separate layout and add the linked js and css files to the project?

1-Does Blazor AppServer have this feature? Or should I use Blazor Web Assembly?

2-If you know a tutorial on this topic, introduce it for all friends to use?

3-I do not know how to use the template code to the project when I create the layer!!

Startup Configure :

 app.UseEndpoints(endpoints =>
        {
            endpoints.MapBlazorHub();
            endpoints.MapFallbackToPage("/_Host");
            endpoints.MapFallbackToPage("~/AdminPanel/{*clientroutes:nonfile}", "/_AdminLayout");
        });


Solution 1:[1]

You can do it conditionally in _Host.cshtml to load different component for different audience according to Authentication Data. Another approach is to write a condition in program.cs as yourself you do but inside a if block. For example for two different environment you can do following:

if (env.IsDevelopment()) {
endpoints.MapFallbackToPage("/_Host");
} else {
endpoints.MapFallbackToPage("/_HostForAdmin");
}

To do it according to user information you can check it as:

app.Use( async (ctx,next)=> 
{
    if (ctx.User.IsInRole("admin")) {
        app.MapFallbackToPage("/_Host");
    } else
    {

    }
    await next(ctx);
});

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mehdi Mowlavi