Created
July 30, 2020 08:11
-
-
Save ClaraLeigh/c253db5cd04cb3063802b4468408a636 to your computer and use it in GitHub Desktop.
Laravel Nova - Livewire Hack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add middleware: | |
... | |
'mynova' => [ | |
'web', | |
Authenticate::class, | |
DispatchServingNovaEvent::class, | |
BootTools::class, | |
Authorize::class, | |
] | |
... | |
(obviously add this to your routes) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('admin.nova-livewire') | |
@section('body') | |
<div> | |
@livewire('example') | |
</div> | |
@endsection |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('nova::layout') | |
@section('content') | |
<loading ref="loading"></loading> | |
@yield('body') | |
@endsection | |
@push('header') | |
@livewireStyles | |
@endpush | |
@push('scripts') | |
<script> | |
window.addEventListener("click", function (event) { | |
var anchor = event.target.closest("a"); // Find closest Anchor (or self) | |
if (typeof anchor !== 'undefined' && anchor) { | |
window.location = anchor.getAttribute('href'); | |
} | |
}); | |
window.addEventListener( "pageshow", function ( event ) { | |
var historyTraversal = event.persisted || | |
( typeof window.performance != "undefined" && | |
window.performance.navigation.type === 2 ); | |
if ( historyTraversal ) { | |
// Handle page restore. | |
window.location.reload(); | |
} | |
}); | |
history.replaceState({ | |
livewire: true | |
}, document.title, window.location.pathname); | |
</script> | |
@livewireScripts | |
@endpush |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Before `</head>` add: | |
@stack('header') | |
Before `</body>` add: | |
<script> | |
window.onpopstate = function(event) { | |
if (typeof event.state !== 'undefined' && typeof event.state["livewire"] !== 'undefined') { | |
location.reload(); | |
} | |
}; | |
</script> | |
@stack('scripts') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is super hacky and probably riddled with bugs.
I made this because I have just moved to nova and don't have time to re-write my livewire components.
I hope this helps anyone trying to do the same thing or just get you somewhere as I couldn't figure out how to do it using cards or resource tools.