Layout is an important part in website development process. It's impact directly to the user interface and user experience. This tutorial includes:
RouteView.@layout directive.LayoutView.You can download the example code used in this topic on GitHub.
Your component will have one tag or many tags, let's call it component content. Layout is how you wrap your component content. Each layout has a @Body property which is the placeholder of the wrapping component. The following image illustrate what a layout is:

Layout in Blazor is a wrapper for a component, not just a website page.
Based on the personality of a layout, you can split the layout into 2 types:
Shared folder.LayoutComponentBase. Add the following code to the directive section of your component.@inherits LayoutComponentBase
@Body as the placeholder of the wrapping component. For example:<div class="bg-dark text-light">
    @Body
</div>
RouteViewYou can use RouteView to set the default layout for your website. To use RouteView, navigate to App.razor and update the DefaultLayout parameter of the RouteView component. For example:
<RouteView RouteData="routeData" DefaultLayout="typeof(SecondaryLayout)" />
You can group similar Dependent components (see Component types section in Blazor WebAssembly Component .NET 6) into a folder. Furthermore, instead of set a layout for each component, you can set the default layout for all the components in the same folder and its subfolders. Assuming you have the following folder structure:

Create a new component with the name _Imports.razor in the folder you want to set default layout for all components inside. Add @layout directive at the directive section of the component. For example:
@layout FolderLayout
You need to name your component exactly _Imports.razor because it is a special component.

There is a default_Imports.razorwhich located at the same levelApp.razor. Do not put@layoutdirective there. Otherwise, you will have infinity loop.
@layout directive@layout directive at the directive section of the component. For example:@layout PrimaryLayout <h3>MyComponent</h3>
LayoutView<LayoutView Layout="typeof(DarkLayout)">
    <Index></Index>
</LayoutView>
<LayoutView Layout="typeof(LightLayout)">
    <Index></Index>
</LayoutView>

RouteView is the first in the chain, which means anything later will override RouteView. LayoutView is the last in the chain, which means nothing can override LayoutView.