Skip to content

API Proposal: BasePath component for Blazor #66388

@javiercn

Description

@javiercn

Background and Motivation

Blazor apps hosted under subpaths (e.g., /dashboard) require a <base href=""> element with the correct path. This currently requires manual editing or per-app JavaScript workarounds, which are inconsistent across hosting models and easy to break during deployment. The BasePath component centralizes how Blazor apps compute their base URI by rendering a <base> element whose href value matches the current request path base.

Source: PR #64590, fixes #6818.

Proposed API

namespace Microsoft.AspNetCore.Components.Endpoints;

+ public sealed class BasePath : IComponent
+ {
+ }

Note: BasePath has no public parameters; it renders based on NavigationManager.BaseUri at runtime.

Usage Examples

@using Microsoft.AspNetCore.Components.Endpoints

<head>
    <BasePath />
    <link href="app.css" rel="stylesheet" />
</head>

Replaces:

<base href="/" />

Alternative Designs

Manual <base href=""> edits or per-app JavaScript. These workarounds were inconsistent across hosting models.

Risks

None — additive component. Existing <base href> usage continues to work unchanged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-proposalapi-ready-for-reviewAPI is ready for formal API review - https://github.com/dotnet/apireviewsarea-blazorIncludes: Blazor, Razor Components

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions