Add NavigationManager.GetUriWithHash() extension method#64615
Add NavigationManager.GetUriWithHash() extension method#64615ilonatommy merged 7 commits intomainfrom
Conversation
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a new GetUriWithHash() extension method to NavigationManager to address a longstanding issue with hash fragment URLs in Blazor applications. When a <base> element is used in the HTML document, relative hash URLs resolve against the base URI rather than the current document location, making it difficult to create in-page navigation links. The new API solves this by constructing absolute URIs with hash fragments relative to the current location.
Key Changes:
- Added
NavigationManager.GetUriWithHash()extension method that adds, updates, or removes hash fragments from the current URI - Comprehensive XML documentation with usage examples
- Full test coverage including edge cases for hash manipulation
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/Components/Components/src/NavigationManagerExtensions.cs |
Implements the new GetUriWithHash() method with proper null checking, hash prepending logic, and URI manipulation |
src/Components/Components/test/NavigationManagerTest.cs |
Adds comprehensive test coverage for the new method including hash addition, replacement, removal, and null parameter handling |
src/Components/Components/src/PublicAPI.Unshipped.txt |
Documents the new public API surface for tracking purposes |
Co-authored-by: javiercn <6995051+javiercn@users.noreply.github.com>
|
@javiercn, it happened again. Copilot is producing descriptions with random issue number next to "fixes" keyword. This one has nothing to do with 41773 (I won't be linking it to avoid confusion). |
|
@copilot merge it with main and resolve conflicts |
…nmanager-geturiwithhash
…non-root base URIs Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
|
@copilot remove src/submodules/googletest changes, it would be best if you check it out to main branch |
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Co-authored-by: ilonatommy <32700855+ilonatommy@users.noreply.github.com>
Reverted the googletest submodule changes to match the main branch (d3084c9 and b2a88c4). The submodule pointer has been restored to commit cb1bd881, which is the correct commit from the main branch. |
hashparameter non-nullable (nowstringinstead ofstring?)<base href="/subdir/">)Summary of changes
PublicAPI.Unshipped.txtGetUriWithHashsignature to use non-nullablestring hashparameterArgumentNullException.ThrowIfNull(hash)checkstring.IsNullOrEmpty(hash)tohash.Length == 0💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.