Blazor Web can use BasePath component instead of <base href="">#64590
Merged
ilonatommy merged 10 commits intodotnet:mainfrom Dec 3, 2025
Merged
Blazor Web can use BasePath component instead of <base href="">#64590ilonatommy merged 10 commits intodotnet:mainfrom
BasePath component instead of <base href="">#64590ilonatommy merged 10 commits intodotnet:mainfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new BasePath component that allows Blazor Web applications to dynamically set the <base href=""> element based on the current request path base, providing an alternative to hardcoded base tags. The component intelligently determines the base path from multiple sources with a clear precedence order.
Key changes:
- Added
BasePathcomponent with automatic path base detection fromIHttpContextAccessor,NavigationManager, and fallback options - Introduced a new dependency on
Microsoft.AspNetCore.Http.Abstractionsfor accessing request context - Exposed new public API surface including the
BasePathclass and itsHrefandFallbackHrefproperties
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/Components/Web/src/Head/BasePath.cs | New sealed component that renders a <base> element with href computed from request PathBase, explicit parameters, or NavigationManager |
| src/Components/Web/src/PublicAPI.Unshipped.txt | Adds public API entries for the new BasePath component and its properties |
| src/Components/Web/src/Microsoft.AspNetCore.Components.Web.csproj | Adds reference to Microsoft.AspNetCore.Http.Abstractions for IHttpContextAccessor support |
javiercn
requested changes
Dec 2, 2025
src/Components/Web/test/Microsoft.AspNetCore.Components.Web.Tests.csproj
Outdated
Show resolved
Hide resolved
src/Components/Web/src/Microsoft.AspNetCore.Components.Web.csproj
Outdated
Show resolved
Hide resolved
ilonatommy
commented
Dec 2, 2025
src/Components/Endpoints/test/Microsoft.AspNetCore.Components.Endpoints.Tests.csproj
Show resolved
Hide resolved
javiercn
approved these changes
Dec 3, 2025
39 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Proposal addressing #6818 by introducing a reusable
BasePathcomponent that centralizes how Blazor apps compute their<base>URI when hosted under subpaths.Background
Routing case preservation for apps mounted at
/dashboardor similar previously required manual<base href>edits or per-app JavaScript. Those workarounds were inconsistent across hosting models and easy to break during deployment. Moving the logic into the Endpoints package givesBlazor Weba single, framework-owned solution while standaloneWebAssemblyapps keep using their static<base />.This gives developers a first-class, framework-supported answer instead of per-app workarounds mentioned throughout #6818.
Changes
Public API
Implementation Details
BasePathimplementsIComponent, renders a<base>element viaRenderHandle, and resolves the href fromNavigationManager.BaseUri./if the base URI cannot be parsed, but otherwise mirrors both casing and multi-segment paths exposed by the endpoint pipeline.NavigationManager.src/Components/Endpoints/src/Routing/BasePath.csand will share the directory with future routing-related document helpers.Tests
The component is covered with unit tests and passed manual testing. Adding e2e test seems too heavy for this kind of change.
API usage
Fixes #6818.