Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 25, 2025

Fixes #[issue_number]

The Blazor Web App template was inconsistent with other Blazor templates by requiring the "Layout." namespace prefix when referencing MainLayout in Routes.razor, even though the Layout namespace was already imported in _Imports.razor.

Problem

Before this fix, the Blazor Web App template generated Routes.razor with:

<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
<AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)">

This was inconsistent with the Blazor WebAssembly template, which correctly uses:

<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>

The inconsistency was causing documentation issues and creating a poor developer experience.

Solution

This change removes the unnecessary "Layout." prefix from both RouteView and AuthorizeRouteView components in Routes.razor:

- <AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)">
+ <AuthorizeRouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)">

- <RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)" />
+ <RouteView RouteData="routeData" DefaultLayout="typeof(MainLayout)" />

The Layout namespace is already properly imported in _Imports.razor through conditional compilation directives that handle all template scenarios:

  • Server-only: @using ProjectName.Components.Layout
  • WebAssembly with per-page interactivity: @using ProjectName.Components.Layout
  • WebAssembly with global interactivity: @using ProjectName.Client.Layout

Testing

Verified that all major template configurations work correctly:

  • ✅ Server-only (dotnet new blazor)
  • ✅ WebAssembly per-page (dotnet new blazor -int WebAssembly)
  • ✅ WebAssembly global (dotnet new blazor -int WebAssembly -ai)
  • ✅ Authentication (dotnet new blazor -au Individual)

All generated projects compile successfully and behave consistently with other Blazor templates.

Original prompt

This section details on the original issue you should resolve

<issue_title>Blazor Web App template: The Layout folder (namespace) isn't present in the _Imports file</issue_title>
<issue_description>### Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

In prior releases (Blazor Server), the Shared folder namespace was placed in the _Imports file. This release for BWAs, only the Components folder is present. This results in the incongruous situation where "Layout." has to be supplied on DefaultLayout ...

<RouteView RouteData="@routeData" DefaultLayout="@typeof(Layout.MainLayout)" />

... which wasn't required before and still isn't required for Blazor WebAssembly apps. It's breaking the docs and requiring further versioned content.

Describe the solution you'd like

Consider adding it to the _Imports file ...

@using BlazorWeb_CSharp.Components.Layout

Remove "Layout." from the two DefaultLayout params in Routes.razor.

Additional context

BTW .... It seems like if the components folder is plural (Components) and the routable components folder is plural (Pages) that the layout folder name should also be plural (Layouts).</issue_description>

<agent_instructions>Add @using BlazorWeb_CSharp.Components.Layout to _Imports.razor

Remove "Layout." from the two DefaultLayout params in Routes.razor.</agent_instructions>

Comments on the Issue (you are @copilot in this section)

@ Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.</comment_new>
<comment_new>@
Thanks for contacting us.

We're moving this issue to the .NET 9 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.</comment_new>

Fixes #52478

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor

Greetings human! You've submitted a PR that modifies code that is shared with https://github.com/dotnet/runtime . Please make sure you synchronize this code with the changes in that repo!

Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Blazor Web App template: The Layout folder (namespace) isn't present in the _Imports file Fix Blazor Web App template: Remove Layout namespace prefix from Routes.razor Sep 25, 2025
@Copilot Copilot AI requested a review from javiercn September 25, 2025 12:11
Copilot finished work on behalf of javiercn September 25, 2025 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blazor Web App template: The Layout folder (namespace) isn't present in the _Imports file
2 participants