Workaround Chrome navigation issue (#10839)

Thanks @javiercn and @SteveSandersonMS!
This commit is contained in:
Steve Sanderson 2019-06-06 01:43:20 +01:00 committed by Artak
parent 23d1d11dda
commit 3697b4704b
6 changed files with 55 additions and 2 deletions

View File

@ -14941,9 +14941,19 @@ function enableNavigationInterception() {
function navigateTo(uri, forceLoad) {
var absoluteUri = toAbsoluteUri(uri);
if (!forceLoad && isWithinBaseUriSpace(absoluteUri)) {
// It's an internal URL, so do client-side navigation
performInternalNavigation(absoluteUri, false);
}
else if (forceLoad && location.href === uri) {
// Force-loading the same URL you're already on requires special handling to avoid
// triggering browser-specific behavior issues.
// For details about what this fixes and why, see https://github.com/aspnet/AspNetCore/pull/10839
var temporaryUri = uri + '?';
history.replaceState(null, '', temporaryUri);
location.replace(uri);
}
else {
// It's either an external URL, or forceLoad is requested, so do a full page load
location.href = uri;
}
}

View File

@ -2507,9 +2507,19 @@ function enableNavigationInterception() {
function navigateTo(uri, forceLoad) {
var absoluteUri = toAbsoluteUri(uri);
if (!forceLoad && isWithinBaseUriSpace(absoluteUri)) {
// It's an internal URL, so do client-side navigation
performInternalNavigation(absoluteUri, false);
}
else if (forceLoad && location.href === uri) {
// Force-loading the same URL you're already on requires special handling to avoid
// triggering browser-specific behavior issues.
// For details about what this fixes and why, see https://github.com/aspnet/AspNetCore/pull/10839
var temporaryUri = uri + '?';
history.replaceState(null, '', temporaryUri);
location.replace(uri);
}
else {
// It's either an external URL, or forceLoad is requested, so do a full page load
location.href = uri;
}
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -65,8 +65,17 @@ export function navigateTo(uri: string, forceLoad: boolean) {
const absoluteUri = toAbsoluteUri(uri);
if (!forceLoad && isWithinBaseUriSpace(absoluteUri)) {
// It's an internal URL, so do client-side navigation
performInternalNavigation(absoluteUri, false);
} else if (forceLoad && location.href === uri) {
// Force-loading the same URL you're already on requires special handling to avoid
// triggering browser-specific behavior issues.
// For details about what this fixes and why, see https://github.com/aspnet/AspNetCore/pull/10839
const temporaryUri = uri + '?';
history.replaceState(null, '', temporaryUri);
location.replace(uri);
} else {
// It's either an external URL, or forceLoad is requested, so do a full page load
location.href = uri;
}
}

View File

@ -301,6 +301,30 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
Browser.Equal("Not a component!", () => Browser.FindElement(By.Id("test-info")).Text);
}
[Fact]
public void CanGoBackFromNotAComponent()
{
SetUrlViaPushState("/");
// First go to some URL on the router
var app = MountTestComponent<TestRouter>();
app.FindElement(By.LinkText("Other")).Click();
Browser.True(() => Browser.Url.EndsWith("/Other"));
// Now follow a link out of the SPA entirely
app.FindElement(By.LinkText("Not a component")).Click();
Browser.Equal("Not a component!", () => Browser.FindElement(By.Id("test-info")).Text);
Browser.True(() => Browser.Url.EndsWith("/NotAComponent.html"));
// Now click back
// Because of how the tests are structured with the router not appearing until the router
// tests are selected, we can only observe the test selector being there, but this is enough
// to show we did go back to the right place and the Blazor app started up
Browser.Navigate().Back();
Browser.True(() => Browser.Url.EndsWith("/Other"));
WaitUntilTestSelectorReady();
}
[Fact]
public void CanNavigateProgrammatically()
{