Skip to content

Commit 22fbeac

Browse files
Clarify IUriHelper GetAbsoluteUrl behavior. Fixes #9717 (#12422)
* E2E test showing it already works when navigating inside the app * E2E test showing expected behavior around both sides of prerendering
1 parent e043f93 commit 22fbeac

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/Components/test/E2ETest/ServerExecutionTests/PrerenderingTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,26 @@ public void CanUseJSInteropFromOnAfterRenderAsync()
5555
Browser.Equal("Hello from interop call", () => Browser.FindElement(By.Id("val-set-by-interop")).GetAttribute("value"));
5656
}
5757

58+
[Fact]
59+
public void CanReadUrlHashOnlyOnceConnected()
60+
{
61+
var urlWithoutHash = "prerendered/show-uri?my=query&another=value";
62+
var url = $"{urlWithoutHash}#some/hash?tokens";
63+
64+
// The server doesn't receive the hash part of the URL, so you can't
65+
// read it during prerendering
66+
Navigate(url);
67+
Browser.Equal(
68+
_serverFixture.RootUri + urlWithoutHash,
69+
() => Browser.FindElement(By.TagName("strong")).Text);
70+
71+
// Once connected, you do have access to the full URL
72+
BeginInteractivity();
73+
Browser.Equal(
74+
_serverFixture.RootUri + url,
75+
() => Browser.FindElement(By.TagName("strong")).Text);
76+
}
77+
5878
private void BeginInteractivity()
5979
{
6080
Browser.FindElement(By.Id("load-boot-script")).Click();

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,19 @@ public void UsingUriHelperWithoutRouterWorks()
388388
Browser.Equal(initialUrl, () => app.FindElement(By.Id("test-info")).Text);
389389
}
390390

391+
[Fact]
392+
public void UriHelperCanReadAbsoluteUriIncludingHash()
393+
{
394+
var app = MountTestComponent<UriHelperComponent>();
395+
Browser.Equal(Browser.Url, () => app.FindElement(By.Id("test-info")).Text);
396+
397+
var uri = "/mytestpath?my=query&another#some/hash?tokens";
398+
var expectedAbsoluteUri = $"{_serverFixture.RootUri}subdir{uri}";
399+
400+
SetUrlViaPushState(uri);
401+
Browser.Equal(expectedAbsoluteUri, () => app.FindElement(By.Id("test-info")).Text);
402+
}
403+
391404
[Fact]
392405
public void CanArriveAtRouteWithExtension()
393406
{
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@page "/show-uri"
2+
@inject IUriHelper UriHelper
3+
The current URL is <strong>@UriHelper.GetAbsoluteUri()</strong>

0 commit comments

Comments
 (0)