rahmanramsi/livewire-spa
Livewire SPA adds smooth single-page-app style navigation to Laravel Livewire apps, swapping components and updating the URL without full page reloads. Lightweight package for faster, seamless page transitions.
composer require rahmanramsi/livewire-spa. This is a pre-1.0 package (0.0.x), so pin the exact version in composer.json until you have verified the changelog.composer show livewire/livewire.php artisan vendor:publish --tag=livewire-spa-config (verify the tag in the package README).0.0.5, you may instead use the package’s root component that renders the entire HTML document (<!DOCTYPE html>, <head>, <body>). If you use it, include @livewireStyles in the head and @livewireScripts before </body> inside that component.php artisan make:livewire SpaApp, then conditionally render page components inside it (@livewire($currentPage)). Use wire:navigate on links (or the package’s navigation helper) so clicks swap page content without a full browser reload.0.0.5 PR (“Full html component”) to see the exact component name and required markup. The root/full-HTML component is now the primary integration point.<html>, <head>, and <body>. Inside the body, render the active page component dynamically. Keep the root component small—only global state, navigation state, and layout concerns.request()->path() and resolving a component class/name. Direct visits and SPA navigations then share the same entry point.wire:navigate on internal links, or the package’s link helper if provided. For programmatic navigation, call the package’s navigate method or dispatch a Livewire event that the root listens for. Ensure external links and file downloads are excluded from SPA interception.<html>/<body>), so they can be swapped. If you still need Blade layouts for non-SPA pages, keep those routes outside the root component.$dispatch, #[On]) for page-to-root or page-to-page communication.@script/@assets in Livewire 3 or dispatch a browser event after navigation (livewire:navigated) and initialize there./users/1 renders the same page as an in-app navigation. Use wire:key on the dynamic page component to force a clean remount when the page changes.wire:loading indicators around the page container. For smoother transitions, add CSS with wire:navigate’s progress bar or the package’s built-in progress if available. Test browser back/forward: the root must respond to history changes.0.0.5 adds a full HTML component, which is a meaningful architectural feature. Expect API changes in 0.0.x. Pin the version and read the diff before upgrading; the full HTML component may change how layouts are expected to be structured.@extends/@section Blade layouts together with the full HTML component for the same route. The component replaces the layout. If you see duplicated <html> tags or missing Livewire scripts, you likely have both a Blade layout and the full HTML component rendering.@livewireStyles/@livewireScripts: In a full HTML component, these are easy to forget. Without them, Livewire requests fail and wire:navigate may not work. Put @livewireStyles in <head> and @livewireScripts before </body>.<script> tags in swapped content. Move initialization to Livewire’s @script or listen for livewire:navigated. Alpine.js components may need x-init or a re-init hook after navigation.mount().livewire:navigating, livewire:navigated) to hook analytics, scroll restoration, or third-party widget initialization.wire:key to avoid stale child state when switching between pages.How can I help you explore Laravel packages today?