You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using for Inertia visits if the route props are deferred Inertia makes second 'get' request to previous route instead of the new one. As stated in Inertia docs the callback shoud
be executed in a separate request AFTER the initial page render.
so it does load the new page but redirects back to previous route, or to be more specific - displays previous route (that was rendered). It happens with Inertia Links and Inertia manual visits like router.visit().
Example:
I'm on /dashboard route
Clicking on <Link> with :href="route('users')"
Users page loads showing Loading... title from Deferred fallback
Inertia redirects back to /dashboard (or any previous route that was before clicking Link tag)
It doesn't happen on raw url requests (pasting url) or when using <a> tags. For example when going to my-domain.com/users it renders Loading... and then shows the data
returnInertia::render('Users', [
'users' => Inertia::defer(fn() => [
'firstname' => 'TEST' // Just for testing purposes returns plain data
]),
]);
Edit:
I discovered this has to do with placing \Inertia\EncryptHistoryMiddleware::class in the app.php withMiddleware for all routes. After some debugging I found using encrypt middleware on a route with deferred props causes the redirect problem.
The text was updated successfully, but these errors were encountered:
TymoteuszNachtman
changed the title
[v2.x] Inertia::defer() redirects to previous route upon <Link> visits
[v2.x] Problem with Inertia::defer() and encryptHistory() upon <Link> visits
Nov 20, 2024
Version:
@inertiajs/vue3
version: 2.0.0-beta.2The problem:
When using for Inertia visits if the route props are deferred Inertia makes second 'get' request to previous route instead of the new one. As stated in Inertia docs the callback shoud
so it does load the new page but redirects back to previous route, or to be more specific - displays previous route (that was rendered). It happens with Inertia Links and Inertia manual visits like
router.visit()
.Example:
/dashboard
route<Link>
with:href="route('users')"
Loading...
title from Deferred fallback/dashboard
(or any previous route that was before clicking Link tag)It doesn't happen on raw url requests (pasting url) or when using
<a>
tags. For example when going to my-domain.com/users it renders Loading... and then shows the dataUsers.vue (fragment)
Laravel route:
Edit:
I discovered this has to do with placing
\Inertia\EncryptHistoryMiddleware::class
in theapp.php
withMiddleware for all routes. After some debugging I found usingencrypt
middleware on a route with deferred props causes the redirect problem.The text was updated successfully, but these errors were encountered: