Skip to content
代码片段 群组 项目
提交 3697b470 编辑于 作者: Steve Sanderson's avatar Steve Sanderson 提交者: Artak
浏览文件

Workaround Chrome navigation issue (#10839)

Thanks @javiercn and @SteveSandersonMS!
上级 23d1d11d
No related branches found
No related tags found
无相关合并请求
...@@ -14941,9 +14941,19 @@ function enableNavigationInterception() { ...@@ -14941,9 +14941,19 @@ function enableNavigationInterception() {
function navigateTo(uri, forceLoad) { function navigateTo(uri, forceLoad) {
var absoluteUri = toAbsoluteUri(uri); var absoluteUri = toAbsoluteUri(uri);
if (!forceLoad && isWithinBaseUriSpace(absoluteUri)) { if (!forceLoad && isWithinBaseUriSpace(absoluteUri)) {
// It's an internal URL, so do client-side navigation
performInternalNavigation(absoluteUri, false); 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 { else {
// It's either an external URL, or forceLoad is requested, so do a full page load
location.href = uri; location.href = uri;
} }
} }
......
...@@ -2507,9 +2507,19 @@ function enableNavigationInterception() { ...@@ -2507,9 +2507,19 @@ function enableNavigationInterception() {
function navigateTo(uri, forceLoad) { function navigateTo(uri, forceLoad) {
var absoluteUri = toAbsoluteUri(uri); var absoluteUri = toAbsoluteUri(uri);
if (!forceLoad && isWithinBaseUriSpace(absoluteUri)) { if (!forceLoad && isWithinBaseUriSpace(absoluteUri)) {
// It's an internal URL, so do client-side navigation
performInternalNavigation(absoluteUri, false); 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 { else {
// It's either an external URL, or forceLoad is requested, so do a full page load
location.href = uri; location.href = uri;
} }
} }
......
...@@ -65,8 +65,17 @@ export function navigateTo(uri: string, forceLoad: boolean) { ...@@ -65,8 +65,17 @@ export function navigateTo(uri: string, forceLoad: boolean) {
const absoluteUri = toAbsoluteUri(uri); const absoluteUri = toAbsoluteUri(uri);
if (!forceLoad && isWithinBaseUriSpace(absoluteUri)) { if (!forceLoad && isWithinBaseUriSpace(absoluteUri)) {
// It's an internal URL, so do client-side navigation
performInternalNavigation(absoluteUri, false); 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 { } else {
// It's either an external URL, or forceLoad is requested, so do a full page load
location.href = uri; location.href = uri;
} }
} }
......
...@@ -301,6 +301,30 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests ...@@ -301,6 +301,30 @@ namespace Microsoft.AspNetCore.Components.E2ETest.Tests
Browser.Equal("Not a component!", () => Browser.FindElement(By.Id("test-info")).Text); 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] [Fact]
public void CanNavigateProgrammatically() public void CanNavigateProgrammatically()
{ {
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册