egil / Htmxor

Supercharges Blazor static server side rendering (SSR) by seamlessly integrating the Htmx.org frontend library.
MIT License
109 stars 12 forks source link

Map from NavigationManager to HX-headers #19

Closed egil closed 2 months ago

egil commented 3 months ago

How should we map between the NavigationManager.NavigateTo calls with and without NavigationOptions and HX- headers?

My current thinking is:

Uri kind ForceLoad ReplaceHistoryEntry HX headers
relative uri false false HX-Location: relative uri
relative uri true false HX-Redirect: relative uri
relative uri false true HX-Replace-Url: relative uri
relative uri true true HX-Redirect: relative uri, HX-Replace-Url: relative uri
another domain uri true/false true/false HX-Redirect: another domain uri (assume implicit HX-Push-Url)

If the NavigateTo call happens during a non-hx request, a standard 302 redirect status code is used with the absolute url.

egil commented 2 months ago

These are the current way htmxor maps blazors navigation manager options. Ill close this issue. If it turns out this is not ideal, we can revisit it:

var navOptions = navigationException.Options;
if (htmxContext.Request.IsHtmxRequest)
{
    if (navOptions.ForceLoad)
    {
        htmxContext.Response.Redirect(navigationException.RequestedLocation);

        if (navOptions.ReplaceHistoryEntry)
        {
            htmxContext.Response.ReplaceUrl(navigationException.RequestedLocation);
        }
    }
    else
    {
        if (navOptions.ReplaceHistoryEntry)
        {
            htmxContext.Response.ReplaceUrl(navigationException.RequestedLocation);
        }
        else
        {
            htmxContext.Response.Redirect(navigationException.RequestedLocation);
        }
    }
}
else
{
    httpContext.Response.Redirect(navigationException.Location);
}