Skip to content

Clarify IUriHelper GetAbsoluteUrl behavior. Fixes #9717 #12422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions src/Components/test/E2ETest/Tests/RoutingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,19 @@ public void UsingUriHelperWithoutRouterWorks()
Browser.Equal(initialUrl, () => app.FindElement(By.Id("test-info")).Text);
}

[Fact]
public void UriHelperCanReadAbsoluteUriIncludingHash()
{
var app = MountTestComponent<UriHelperComponent>();
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()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@page "/show-uri"
@inject IUriHelper UriHelper
The current URL is <strong>@UriHelper.GetAbsoluteUri()</strong>