Skip to content

Route Attribute not working as expected on ComponentBase / Blazor #39329

@sipi41

Description

@sipi41

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I'm creating a simple component that inherits from a ComponentBase class, and my understanding is that I can use the Route attribute in the base class instead of the @page directive, unfortunately when I do that, I don't get an error but the page is just blank

BLAZOR COMPONENT:

@inherits EmployeeListBase
<h3>Employee List</h3>

COMPONENT CLASS

using EmployeeManagement.Models;
using Microsoft.AspNetCore.Components;

namespace EmployeeManagement.Web.Pages
{
    [Route("/")]
    public class EmployeeListBase : ComponentBase
    {
        public IEnumerable<Employee> Employees { get; set; } = new List<Employee>();

    }
}

So basically, this should act as the root page of the razor web, instead, it just displays a blank page, no h3 text, nothing, just blank as follow

image

Expected Behavior

If I don't use the Route attribute on the base class and use the @page directive in the component, then it work as expected:

image

According to the docs at https://docs.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-6.0 in the Routing section it states the following:

When a Razor file with an @page directive is compiled, the generated class is given a RouteAttribute specifying the route template.

Thank you so much for all your help! If I'm doing something wrong, PLEASE let me know, thank you.:-)

Steps To Reproduce

No response

Exceptions (if any)

No exceptions, just a blank page is returned.

.NET Version

6

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor Componentsfeature-blazor-routingFeatures related to routing in Blazor applications

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions