From 66515e3465f4deb6429752975f86329592254f49 Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Tue, 1 Aug 2023 13:15:42 +0200 Subject: [PATCH] enable navigation render mode server --- .../Web.JS/src/Services/NavigationManager.ts | 2 +- .../EnhancedNavigationTest.cs | 15 +++++++++++++++ .../PageWithServerRenderModeCanNavigate.razor | 15 +++++++++++++++ .../Shared/EnhancedNavLayout.razor | 1 + 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/EnhancedNav/PageWithServerRenderModeCanNavigate.razor diff --git a/src/Components/Web.JS/src/Services/NavigationManager.ts b/src/Components/Web.JS/src/Services/NavigationManager.ts index b69e4446ba560..0c5f4d130323b 100644 --- a/src/Components/Web.JS/src/Services/NavigationManager.ts +++ b/src/Components/Web.JS/src/Services/NavigationManager.ts @@ -115,7 +115,7 @@ function navigateToFromDotNet(uri: string, options: NavigationOptions): void { function navigateToCore(uri: string, options: NavigationOptions, skipLocationChangingCallback = false): void { const absoluteUri = toAbsoluteUri(uri); - if (!options.forceLoad && isWithinBaseUriSpace(absoluteUri)) { + if (!options.forceLoad && isWithinBaseUriSpace(absoluteUri) && hasInteractiveRouter()) { performInternalNavigation(absoluteUri, false, options.replaceHistoryEntry, options.historyEntryState, skipLocationChangingCallback); } else { // For external navigation, we work in terms of the originally-supplied uri string, diff --git a/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs b/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs index 8db7d01ba9329..38435be91419a 100644 --- a/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs +++ b/src/Components/test/E2ETest/ServerRenderingTests/EnhancedNavigationTest.cs @@ -144,6 +144,21 @@ public void CanFollowAsynchronousExternalRedirectionWhileStreaming() Browser.Contains("microsoft.com", () => Browser.Url); } + [Fact] + public void RenderModeServerCanNavigateToAnotherPage() + { + Navigate($"{ServerPathBase}/nav"); + Browser.Equal("Hello", () => Browser.Exists(By.TagName("h1")).Text); + + Browser.Exists(By.TagName("nav")).FindElement(By.LinkText("Render mode Server navigation")).Click(); + Browser.Equal("Render mode Server can navigate", () => Browser.Exists(By.TagName("h1")).Text); + + Browser.Exists(By.Id("navigate")).Click(); + + Browser.Equal("Hello", () => Browser.Exists(By.TagName("h1")).Text); + Assert.EndsWith("/nav", Browser.Url); + } + private long BrowserScrollY { get => Convert.ToInt64(((IJavaScriptExecutor)Browser).ExecuteScript("return window.scrollY"), CultureInfo.CurrentCulture); diff --git a/src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/EnhancedNav/PageWithServerRenderModeCanNavigate.razor b/src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/EnhancedNav/PageWithServerRenderModeCanNavigate.razor new file mode 100644 index 0000000000000..016c88a2e97cf --- /dev/null +++ b/src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/EnhancedNav/PageWithServerRenderModeCanNavigate.razor @@ -0,0 +1,15 @@ +@page "/nav/render-mode-server-can-navigate" +@inject NavigationManager Nav +@attribute [RenderModeServer] +Render mode Server can navigate + +

Render mode Server can navigate

+ + + +@code { + void Navigate() + { + Nav.NavigateTo("nav"); + } +} diff --git a/src/Components/test/testassets/Components.TestServer/RazorComponents/Shared/EnhancedNavLayout.razor b/src/Components/test/testassets/Components.TestServer/RazorComponents/Shared/EnhancedNavLayout.razor index 542f7e56841b2..c9a2735133dd9 100644 --- a/src/Components/test/testassets/Components.TestServer/RazorComponents/Shared/EnhancedNavLayout.razor +++ b/src/Components/test/testassets/Components.TestServer/RazorComponents/Shared/EnhancedNavLayout.razor @@ -12,6 +12,7 @@ Redirect while streaming | Redirect external while streaming | Error while streaming + Render mode Server navigation
@Body