Redirects
Laravel Livewire Documentation Reference
Since Magewire is heavily inspired by Laravel Livewire, many concepts are either identical or very similar. To avoid duplicating documentation, this page only covers Magewire-specific and platform-specific details. For all general concepts and in-depth explanations, you can refer to the corresponding Laravel Livewire documentation.
A component action can send the browser to another URL by calling $this->redirect(). The redirect
happens after the action finishes — it's queued as an effect on the response and performed by the JS
runtime, so it works the same whether triggered on an initial render or a wire:click update.
Redirecting from an action
use Magewirephp\Magewire\Component;
class SaveAddress extends Component
{
public function save(): void
{
// … persist the address …
$this->redirect('/checkout/payment');
}
}
Pass any URL string. To build a Magento URL, resolve it the usual way (e.g. a UrlInterface
dependency on your component) and hand the result to redirect():
What happens under the hood
redirect() is provided by the SupportRedirects feature. It:
- Stores the target URL on the component's data store.
- On
dehydrate, adds aredirecteffect to the component's snapshot. - Skips the re-render by default — there's no point rendering a component you're navigating away
from. (Controlled by the
livewire.render_on_redirectconfig; off by default.)
The browser receives the redirect effect and performs the navigation.
The $navigate argument
redirect() accepts a second $navigate argument that opts into SPA-style navigation. That
pathway is not ready for use in Magewire yet — call redirect() with a URL only, and let the
browser perform a normal full navigation.
Related
- Actions — where redirects are typically triggered.
- Lifecycle Hooks —
dehydrate, where the redirect effect is added.