Closed egil closed 5 months ago
For now, if there is a <HeadOutlet />
in the component tree, the <PageTitle>
component will render the title element and htmx will pick up on that.
@page "/replace-head-elements"
@inject HtmxContext ctx
@if (ctx.Request.IsHtmxRequest)
{
<head>
<HeadOutlet />
</head>
<PageTitle>Htmx request @DateTimeOffset.UtcNow</PageTitle>
}
else
{
<PageTitle>Normal request</PageTitle>
}
<button hx-get="/replace-head-elements" type="button" hx-target="this" hx-swap="outerHTML">Change title</button>
This is supported by having an hx layout that has includes the headoutlet component. Then the page title component just works.
By default, htmx will update the page's title if it finds a
Since the
<PageTitle>
component is used in Blazor to do the same thing from any page component, we can make the integration work seamlessly by overriding the<PageTitle>
component behavior to write out a<title>
element where it is being added to the component tree, allowing HX to do its magic.That should only happen when Htmxor is processing an HX request. On normal full page loads the
<PageTitle>
component should behave as normal.This can be done by Htmxor including a custom
IComponentActivator
that returns a different component type during HX requests.