maiksch
maiksch

Reputation: 189

HTMX: hx-boost and relative URLs

I have encountered an interesting problem. First, imagine following URL structure:

I configured all 3 pages to have hx-boost="true" on the body tag and use boosted anchor tags for all my navigation.

Here are the simple steps to reprodure my problem:

  1. I load my page on /admin
  2. I navigate to admin/[id] (notice how I use a relative path)
  3. I get navigated to /admin/[id]/scores successfully
  4. I click on a link in the tab bar to navigate "horizontally" to answers (The browser shows /admin/[id]/answers when hovering over the anchor tag)
  5. I get a 404, because HTMX tries to load /answers instead of /admin/[id]/answers

Also the other way around:

  1. I load my page on /admin/[id]/answers
  2. I navigate to /admin (this time with an absolute path)
  3. I get navigated to /admin successfully
  4. I click on a link to admin/[id] (now a relative path again)
  5. I get a 404, because HTMX tries to load /admin/q/[id]/admin/q/[id] (huh?)

Did I miss something in the documentation regarding hx-boost and relative URLs? Because if I remove the hx-boost="true" from my links that navigate "vertically" instead of "horizontally" everything works just fine.

Upvotes: 1

Views: 1556

Answers (1)

David Schmitt
David Schmitt

Reputation: 59375

this looks like https://github.com/bigskysoftware/htmx/issues/1476

Order of hx-boost checking and history pushing causes issues with relative links

at the time of posting the workaround seems to be to disable link boosting.

Upvotes: 1

Related Questions