URL State
Sync state with URL for bookmarkable pages
Live Demo
Try the tabs below and watch your browser's address bar update. You can use back/forward to navigate between states.
Products Tab
This is the products content. Notice the URL hasn't changed yet.
Click another tab to see URL state in action.
ℹ️ Check your browser's address bar as you click tabs
URL State Management
Use hx-push-url to update the browser URL when making HTMX requests.
This enables bookmarkable pages and browser back/forward navigation.
Controller Code
[HttpGet]
public IActionResult Search(string? q, int page = 1)
{
var results = SearchProducts(q, page);
// Push URL with query params
Response.HxPushUrl($"/search?q={q}&page={page}");
return this.SwapResponse()
.WithView("_Results", results)
.Build();
}