Skip to content

Attempt to override layout in subfolder using _Imports.razor makes application hang #60912

Open
@Rob-Houweling

Description

@Rob-Houweling

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

This bug was reported before and was closed but the documentation has not been changed and/or this issue still exists:
#35068

When adding a subfolder to my Blazor app and using an _imports.razor to apply a different Layout to all pages inside the folder, this hangs up the entire site. Folder/file structure:


\Components, etc (default structure, no changes)
\Dashboard
----\Components
--------\Layout
----------DashboardLayout.razor
----\Pages
------Home.razor
--_Imports.razor

The _Imports.razor contains the line:
@layout Components.Layout.DashboardMainLayout

This causes the app to hang, probably due to a recursion issue as stated by @pranavkm in the comments of issue 35068.

In the documentation (https://learn.microsoft.com/en-us/aspnet/core/blazor/components/layouts?view=aspnetcore-9.0#apply-a-layout) however it clearly states that

The @layout Razor directive only applies a layout to routable Razor components with an @page directive

. (see highlighted section !Note) while @pranavkm comments in issue 35068 that

Layouts apply to all components, not just routeable ones

It just doesn't make any sense to move the Layout out of the folder structure where the _Imports.razor is located. So either the documentation should be updated, or the bug (which is it imho) should be fixed.

Expected Behavior

Using a layout which is located in a subfolder of where the _imports.razor file is located should not result in a recursive error because the layout should not be applied to itself or other layout files.

Steps To Reproduce

Minimalistic project which reproduces the issue:
https://github.com/Rob-Houweling/BlazorApp1

browse to /dashboard on the local development site to make the site hang.

Exceptions (if any)

No response

.NET Version

9.0.201

Anything else?

.NET 9.0
Microsoft Visual Studio Professional 2022 (64-bit) - Current
Version 17.13.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocsThis issue tracks updating documentationarea-blazorIncludes: Blazor, Razor Components

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions