naja-js / naja

Modern AJAX library for Nette Framework
https://naja.js.org
MIT License
109 stars 15 forks source link

URL is not updated correctly after async redirect #385

Closed jiripudil closed 7 months ago

jiripudil commented 7 months ago

Bug Report

When the server responds with a redirect that Naja follows asynchronously, the location is incorrectly updated to the original request's URL. I believe the culprit is this coalescing assignment, which preserves href from the first request.

To fix this, I think HistoryHandler could listen to the redirect event and update options.href to the redirected URL 🤔

Ragnarrlothbrok commented 7 months ago

Hi, I would like to contribute to this.

JanRossler commented 7 months ago

I can confirm that updating options.href during redirect event fixes the issue for me:

        naja.redirectHandler.addEventListener('redirect', (event) => {
            event.detail.options.href = event.detail.url;
        });