Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0be84e4
Rise even instead of throwing.
ilonatommy Apr 3, 2025
2e5f7dc
Clean up, delay not needed.
ilonatommy Apr 3, 2025
5ebaaac
Fix typo + test old way of workign as well.
ilonatommy Apr 3, 2025
1ea43be
Update name to be full namespace + remove readonly.
ilonatommy Apr 4, 2025
e9bd57e
Feedback - interactive SSR updates required exposing some methods.
ilonatommy Apr 7, 2025
ebc2537
Fix missing xml.
ilonatommy Apr 7, 2025
dff3c70
Fix build of tests.
ilonatommy Apr 7, 2025
19d3fe9
Fix nullable.
ilonatommy Apr 7, 2025
def3e5c
Feedback - limit public API changes.
ilonatommy Apr 8, 2025
9f79f51
Handle the case when response started.
ilonatommy Apr 8, 2025
e647f2a
Proposal of fixing external navigation.
ilonatommy Apr 9, 2025
5e6d104
Update src/Components/test/testassets/Components.TestServer/RazorComp…
ilonatommy Apr 9, 2025
8413a40
Merge branch 'main' into fix-59451
ilonatommy Apr 10, 2025
9f7fceb
Merge branch 'fix-59451' of https://github.com/ilonatommy/aspnetcore …
ilonatommy Apr 10, 2025
aea9826
Feedback.
ilonatommy Apr 11, 2025
bafa937
More effective stopping of the renderer.
ilonatommy Apr 14, 2025
3521c8f
POST cannot safely redirect like GET does, the body should be preserved.
ilonatommy Apr 14, 2025
a3ca937
Reuse the logic from navigation exception.
ilonatommy Apr 14, 2025
5d7eb68
Editing the ongoing render batch is not possible - for non-streaming …
ilonatommy Apr 14, 2025
69426fd
Missing change for the last commit.
ilonatommy Apr 15, 2025
e0b407c
Rename switch to match http and remote navigator.
ilonatommy Apr 15, 2025
dc45f3e
Adjust test for the new behavior.
ilonatommy Apr 15, 2025
b36db8b
Fix exception - driven navigation.
ilonatommy Apr 15, 2025
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 @@ -7,11 +7,29 @@ namespace Microsoft.AspNetCore.Components.Endpoints;

internal sealed class HttpNavigationManager : NavigationManager, IHostEnvironmentNavigationManager
{
private const string EnableThrowNavigationException = "Microsoft.AspNetCore.Components.Endpoints.HttpNavigationManager.EnableThrowNavigationException";
private static bool ThrowNavigationException =>
AppContext.TryGetSwitch(EnableThrowNavigationException, out var switchValue) && switchValue;

private EventHandler<NavigationEventArgs>? _onNavigateTo;
public event EventHandler<NavigationEventArgs> OnNavigateTo
{
add => _onNavigateTo += value;
remove => _onNavigateTo -= value;
}

void IHostEnvironmentNavigationManager.Initialize(string baseUri, string uri) => Initialize(baseUri, uri);

protected override void NavigateToCore(string uri, NavigationOptions options)
{
var absoluteUriString = ToAbsoluteUri(uri).AbsoluteUri;
throw new NavigationException(absoluteUriString);
if (ThrowNavigationException)
{
throw new NavigationException(absoluteUriString);
}
else
{
_onNavigateTo?.Invoke(this, new NavigationEventArgs(absoluteUriString));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.AspNetCore.Components.Endpoints;

internal class NavigationEventArgs : EventArgs
{
public string Uri { get; }

public NavigationEventArgs(string uri)
{
Uri = uri;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ internal async Task InitializeStandardComponentServicesAsync(
if (navigationManager != null)
{
navigationManager.OnNotFound += SetNotFoundResponse;
if (navigationManager is HttpNavigationManager httpNavigationManager)
{
httpNavigationManager.OnNavigateTo += OnNavigateTo;
}
}

var authenticationStateProvider = httpContext.RequestServices.GetService<AuthenticationStateProvider>();
Expand Down Expand Up @@ -135,6 +139,11 @@ internal async Task InitializeStandardComponentServicesAsync(
}
}

private void OnNavigateTo(object? sender, NavigationEventArgs args)
{
_httpContext.Response.Redirect(args.Uri);
}

private static void InitializeResourceCollection(HttpContext httpContext)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,16 @@ public void CanUseServerAuthenticationStateByDefault()
Browser.Equal("True", () => Browser.FindElement(By.Id("is-in-test-role-1")).Text);
Browser.Equal("True", () => Browser.FindElement(By.Id("is-in-test-role-2")).Text);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void NavigatesWithoutInteractivityByRequestRedirection(bool controlFlowByException)
{
AppContext.SetSwitch("Microsoft.AspNetCore.Components.Endpoints.EnableThrowNavigationException", isEnabled: controlFlowByException);
Navigate($"{ServerPathBase}/routing/ssr-navigate-to");
Browser.Equal("Click submit to navigate to home", () => Browser.Exists(By.Id("test-info")).Text);
Browser.Click(By.Id("redirectButton"));
Browser.Equal("Routing test cases", () => Browser.Exists(By.Id("test-info")).Text);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@page "/routing"
<h3>Routing test cases</h3>
<h3 id="test-info">Routing test cases</h3>

<ul>
<li>
Expand All @@ -24,12 +24,6 @@
<a href="routing/complex-segment(value)">Complex segments</a>
</li>
<li>
<a href="routing/not-found-ssr">Not found page for Static Server Rendering</a>
</li>
<li>
<a href="routing/not-found-webassembly">Not found page for Interactive WebAssembly rendering</a>
</li>
<li>
<a href="routing/not-found-server">Not found page for Interactive Server rendering</a>
<a href="routing/ssr-navigate-to">Redirect on SSR page</a>
</li>
</ul>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@page "/routing/ssr-navigate-to"
@using Microsoft.AspNetCore.Components.Forms
@inject NavigationManager NavigationManager

<p id="test-info">Click submit to navigate to home</p>
<form method="post" @onsubmit="Submit" @formname="MyUniqueFormName">
<AntiforgeryToken />
<button type="submit" id="redirectButton" class="btn btn-primary">Redirect</button>
</form>

@code {
private void Submit()
{
NavigationManager.NavigateTo("/subdir/routing");
}
}

Loading