-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
NavigationManager.NavigateTo does not trigger NavigationException as expected, causing redirection failure when using Htmxor #64
Comments
Thanks for the report. What is interesting is that Can you provide a minimal runnable code sample that I can use to understand your scenario better? |
Using your pizza example code, you can place RedirectManager.RedirectTo("/myorders"); inside the OnInitializedAsync method of Index.razor. Redirections don't seem to work with RedirectManager at all. My idea was to use HTMX redirection via HX-Redirect, which performs a client-side redirect to a new location. I'm unsure how to trigger that directly from the @code section, but it would likely provide a smoother experience, especially with Blazor SSR. In contrast, Blazor's typical way to handle redirection is by throwing a NavigationManagerException, which the framework manages as a redirect. Is there any way to return custom headers from a Blazor component? While Razor pages handle HTML injection well with direct routing, I'm not sure how to modify the headers (e.g., to include an HTTP request header for the HX-Redirect). |
I assume you are talking about the Anyway, Htmxor do the same thing as Blazor SSR, but it provides its own So, the behavior should be identical to Blazor SSR, but do check if your code is using The key part of the HtmxorRenderer that handles this is here: Htmxor/src/Htmxor/Rendering/HtmxorRenderer.Rendering.cs Lines 34 to 102 in d8e09e4
You need access to the // note: this is untested code
[CascadingParameter]
public HtmxContext Context { get; set; }
protected override void OnInitialized()
{
Context.Response.Location("/url/to/other/page");
} Btw. I have been away from this project for a few months, simply have not had the time, so some of this is based on vague memories and may not all be correct. |
Whenever I attempt to call
RedirectManager.RedirectTo
, I expectNavigationManager.NavigateTo(uri)
to throw aNavigationException
, which should be handled by the framework to facilitate the redirection to the specified URL.However, instead of triggering the expected
NavigationException
, what gets triggered is anHtmxorNavigationException
. This leads to anObject reference not set to an instance of an object
error, which ultimately prevents the redirection from working properly when the Htmxor package is active.Expected Behavior:
NavigationManager.NavigateTo(uri)
should trigger theNavigationException
, allowing the framework to handle the redirection seamlessly.Actual Behavior:
HtmxorNavigationException
is thrown instead, causing a null reference error and breaking the redirection flow.Steps to Reproduce:
RedirectManager.RedirectTo
with Htmxor active.NavigationException
is not triggered, and redirection fails due toHtmxorNavigationException
.The text was updated successfully, but these errors were encountered: