Use HX-Target, not HX-Boost for Layout render
HX-Boost is not always sent in all AJAX requests that htmx sends, only those initiated by an element with hx-boost enabled. It was not showing up on requests following an HX-Redirect response. After reading the docs more, I realized HX-Target was what I wanted. If I can see that the request is targeting `#main-content` then I know to only return HTML inside that element. Simple.
This commit is contained in:
@@ -8,7 +8,7 @@ use sqlx::PgPool;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::error::Result;
|
||||
use crate::htmx::HXBoosted;
|
||||
use crate::htmx::HXTarget;
|
||||
use crate::models::entry::Entry;
|
||||
use crate::partials::layout::Layout;
|
||||
use crate::uuid::Base62Uuid;
|
||||
@@ -17,7 +17,7 @@ pub async fn get(
|
||||
Path(id): Path<Base62Uuid>,
|
||||
State(pool): State<PgPool>,
|
||||
State(config): State<Config>,
|
||||
hx_boosted: Option<TypedHeader<HXBoosted>>,
|
||||
hx_target: Option<TypedHeader<HXTarget>>,
|
||||
layout: Layout,
|
||||
) -> Result<Response> {
|
||||
let entry = Entry::get(&pool, id.as_uuid()).await?;
|
||||
@@ -30,7 +30,7 @@ pub async fn get(
|
||||
let content = fs::read_to_string(content_path).unwrap_or_else(|_| "No content".to_string());
|
||||
Ok(layout
|
||||
.with_subtitle(&title)
|
||||
.boosted(hx_boosted)
|
||||
.targeted(hx_target)
|
||||
.render(html! {
|
||||
article {
|
||||
header {
|
||||
|
||||
Reference in New Issue
Block a user