inertiajs / inertia-laravel

The Laravel adapter for Inertia.js.
https://inertiajs.com
MIT License
1.99k stars 222 forks source link

Force app.blade.php to reload #606

Closed darkylmnx closed 3 months ago

darkylmnx commented 3 months ago

There seem to be no way to force a real reload or swap the HTML tag when the blade template has changed. In my blade template I conditionally add a CSS class on the tag when the user is logged in or not.

When I do a logout with router.post('/logout'), the page changes, but the old class is still here, because intertia only patches the <div id="app">;

Same thing goes when I login, the class isn't updated.

For now I have only two solutions which are not ideal:

First solution open to issues if something goes wrong and also not the best in terms of UX, the user first see's the inertia load, then the "normal" reload.

Second solution brings things I wanted to avoid by choosing InertiaJS instead of a standalone SPA, which is manipulating the DOM of the skeleton (something I would normally do in a regular SPA).

Are there any other solutions?

Is there a way to tell inertia "for this request, do a real reload" or something?

rojtjo commented 3 months ago

You should be able to use Inertia::location() for this.

return Inertia::location(route('home'));

// Or pass it a redirect response

return Inertia::location(back());

More info under External redirects in the docs: https://www.inertiajs.com/redirects

driesvints commented 3 months ago

Thanks @rojtjo