Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ed0309d

Browse files
authoredApr 25, 2023
changed behavior of anchor tag with href starting with hash (#47851)
1 parent b3371bb commit ed0309d

File tree

3 files changed

+6
-10
lines changed

3 files changed

+6
-10
lines changed
 

‎src/Components/Web.JS/src/Services/NavigationManager.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ export function attachToEventDelegator(eventDelegator: EventDelegator): void {
9090

9191
if (anchorTarget && canProcessAnchor(anchorTarget)) {
9292
let anchorHref = anchorTarget.getAttribute('href')!;
93-
if (anchorHref.startsWith('#')) {
94-
// Preserve the existing URL but set the hash to match the link that was clicked
95-
anchorHref = `${location.origin}${location.pathname}${location.search}${anchorHref}`;
96-
}
9793

9894
const absoluteHref = toAbsoluteUri(anchorHref);
9995

‎src/Components/test/E2ETest/Tests/RoutingTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,7 @@ public void CanNavigateBetweenPagesWithQueryStrings()
15471547
}
15481548

15491549
[Fact]
1550-
public void AnchorWithHrefStartingWithHash_ScrollsToElementWithIdOnTheSamePage()
1550+
public void AnchorWithHrefContainingHashSamePage_ScrollsToElementWithIdOnTheSamePage()
15511551
{
15521552
SetUrlViaPushState("/");
15531553
var app = Browser.MountTestComponent<TestRouter>();
@@ -1563,7 +1563,7 @@ public void AnchorWithHrefStartingWithHash_ScrollsToElementWithIdOnTheSamePage()
15631563
}
15641564

15651565
[Fact]
1566-
public void AnchorWithHrefContainingHash_NavigatesToPageAndScrollsToElementWithName()
1566+
public void AnchorWithHrefContainingHashAnotherPage_NavigatesToPageAndScrollsToElementWithName()
15671567
{
15681568
SetUrlViaPushState("/");
15691569
var app = Browser.MountTestComponent<TestRouter>();

‎src/Components/test/testassets/BasicTestApp/RouterTest/LongPageWithHash.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@page "/LongPageWithHash"
22
@inject NavigationManager NavigationManager
33

4-
<a id="anchor-test1" href="#test1">Go to test1 on this page</a>
4+
<a id="anchor-test1" href="LongPageWithHash#test1">Go to test1 on this page</a>
55
<br/>
6-
<a id="anchor-test2" href="/subdir/LongPageWithHash2#test2">Go to test2 on LongPageWithHash2 page</a>
6+
<a id="anchor-test2" href="LongPageWithHash2#test2">Go to test2 on LongPageWithHash2 page</a>
77
<br />
88
<button id="navigate-test1" class="btn btn-primary" @onclick="GoToTest1">NavigationManager.NavigatteTo same page #test1</button>
99
<br />
@@ -22,11 +22,11 @@
2222
@code {
2323
void GoToTest1()
2424
{
25-
NavigationManager.NavigateTo("/subdir/LongPageWithHash#test1");
25+
NavigationManager.NavigateTo("LongPageWithHash#test1");
2626
}
2727

2828
void GoToTest2()
2929
{
30-
NavigationManager.NavigateTo("/subdir/LongPageWithHash2#test2");
30+
NavigationManager.NavigateTo("LongPageWithHash2#test2");
3131
}
3232
}

0 commit comments

Comments
 (0)
Please sign in to comment.