-
-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
Environment Details
- PHP Version: 8.3.20
- Laravel Version: 11.37.0
- Vue Version: 3.5.13
- Inertia.js Version: 0.14.0
- Inertia Modal Version: 0.14.0
Bug Report
Description
Laravel redirect()->back();
always redirect to X-InertiaUI-Modal-Base-Url
even when not opening modal.
Steps To Reproduce
- Open a modal using ModalLink
- Close the modal
- Do Inertia Form Call e.g
form.post()
- in the action do
redirect()->back()
Expected Behavior
It should redirect to url in referer
from the request header
Actual Behavior
Instead it always redirects to x-inertiaui-modal-base-url
Feature Request
What feature would you like to see?
Add checking in the Inertiaui Modal Redirector if modal is opened.
Why is it needed?
Correctly handle redirect back
Alternatives Considered
Currently i have created a temporary fix on my local project using custom redirector;
<?php
declare(strict_types=1);
namespace App\Support;
use Illuminate\Routing\Redirector as BaseRedirector;
use InertiaUI\Modal\Modal;
class ModalRedirectorFix extends BaseRedirector
{
/**
* Create a new redirect response to the previous location or a modal base URL.
*
* This method overrides the parent's 'back' method to handle modal-specific redirects.
* If a modal base URL is present in the request header, it redirects to that URL.
* Otherwise, it falls back to the parent's behavior.
*
* @param int $status
* @param array $headers
* @param bool $fallback
* @return \Illuminate\Http\RedirectResponse
*/
public function back($status = 302, $headers = [], $fallback = false)
{
if ($this->generator->getRequest()->hasHeader('x-inertiaui-modal') && $baseUrl = $this->generator->getRequest()->header(Modal::HEADER_BASE_URL)) {
return $this->createRedirect($this->generator->to($baseUrl), $status, $headers);
}
return parent::back($status, $headers, $fallback);
}
}
I added if ($this->generator->getRequest()->hasHeader('x-inertiaui-modal')
.
It will be good if you can patch this in main code instead, so i don't need to use temporary fix.
Metadata
Metadata
Assignees
Labels
No labels