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:
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.
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. TheBasePathcomponent 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
Note:
BasePathhas no public parameters; it renders based onNavigationManager.BaseUriat runtime.Usage Examples
Replaces:
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.