diff --git a/src/Components/test/E2ETest/ServerExecutionTests/PrerenderingTest.cs b/src/Components/test/E2ETest/ServerExecutionTests/PrerenderingTest.cs index b7b6d361c805..9ca210125526 100644 --- a/src/Components/test/E2ETest/ServerExecutionTests/PrerenderingTest.cs +++ b/src/Components/test/E2ETest/ServerExecutionTests/PrerenderingTest.cs @@ -55,6 +55,26 @@ public void CanUseJSInteropFromOnAfterRenderAsync() Browser.Equal("Hello from interop call", () => Browser.FindElement(By.Id("val-set-by-interop")).GetAttribute("value")); } + [Fact] + public void CanReadUrlHashOnlyOnceConnected() + { + var urlWithoutHash = "prerendered/show-uri?my=query&another=value"; + var url = $"{urlWithoutHash}#some/hash?tokens"; + + // The server doesn't receive the hash part of the URL, so you can't + // read it during prerendering + Navigate(url); + Browser.Equal( + _serverFixture.RootUri + urlWithoutHash, + () => Browser.FindElement(By.TagName("strong")).Text); + + // Once connected, you do have access to the full URL + BeginInteractivity(); + Browser.Equal( + _serverFixture.RootUri + url, + () => Browser.FindElement(By.TagName("strong")).Text); + } + private void BeginInteractivity() { Browser.FindElement(By.Id("load-boot-script")).Click(); diff --git a/src/Components/test/E2ETest/Tests/RoutingTest.cs b/src/Components/test/E2ETest/Tests/RoutingTest.cs index ce0dc725e69f..ca79a4c41df7 100644 --- a/src/Components/test/E2ETest/Tests/RoutingTest.cs +++ b/src/Components/test/E2ETest/Tests/RoutingTest.cs @@ -388,6 +388,19 @@ public void UsingUriHelperWithoutRouterWorks() Browser.Equal(initialUrl, () => app.FindElement(By.Id("test-info")).Text); } + [Fact] + public void UriHelperCanReadAbsoluteUriIncludingHash() + { + var app = MountTestComponent(); + Browser.Equal(Browser.Url, () => app.FindElement(By.Id("test-info")).Text); + + var uri = "/mytestpath?my=query&another#some/hash?tokens"; + var expectedAbsoluteUri = $"{_serverFixture.RootUri}subdir{uri}"; + + SetUrlViaPushState(uri); + Browser.Equal(expectedAbsoluteUri, () => app.FindElement(By.Id("test-info")).Text); + } + [Fact] public void CanArriveAtRouteWithExtension() { diff --git a/src/Components/test/testassets/BasicTestApp/ShowUriComponent.razor b/src/Components/test/testassets/BasicTestApp/ShowUriComponent.razor new file mode 100644 index 000000000000..e96f60d52c7c --- /dev/null +++ b/src/Components/test/testassets/BasicTestApp/ShowUriComponent.razor @@ -0,0 +1,3 @@ +@page "/show-uri" +@inject IUriHelper UriHelper +The current URL is @UriHelper.GetAbsoluteUri()