1

我正在尝试访问我的项目中的当前 URL,但它只返回以前的 URL。

这是我所拥有的:

htmx.onLoad(function(content) {
    console.log(window.location.href);
})

知道如何在发出 HTMX 请求后获取当前 URL?

4

1 回答 1

1

HTMXhtmx:pushedIntoHistory在将新 URL 推送到历史记录后发出事件。您可以通过以下方式将事件侦听器附加到它:

htmx.on("htmx:pushedIntoHistory", function(event) {
    console.log(window.location.href)
})
于 2022-01-23T15:25:25.273 回答