Skip to content

Store previous locations for Inertia visits - #888

Open
drewmt wants to merge 1 commit into
inertiajs:3.xfrom
drewmt:fix/inertia-previous-route
Open

Store previous locations for Inertia visits#888
drewmt wants to merge 1 commit into
inertiajs:3.xfrom
drewmt:fix/inertia-previous-route

Conversation

@drewmt

@drewmt drewmt commented Jul 21, 2026

Copy link
Copy Markdown

Summary

Inertia page visits include the X-Requested-With: XMLHttpRequest header, so Laravel's session middleware intentionally skips updating the previous URL and route. As a result, session navigation history can remain stuck on the last full-page visit.

This change stores the current URL and route for Inertia GET visits that Laravel skips, while preserving the existing exclusions for regular AJAX requests, prefetches, precognitive requests, and non-GET requests. Route history is detected as an optional session capability so Laravel 11 remains supported.

Fixes #886.

User impact

Applications can reliably use previousUrl() / previousUri() and, on supported Laravel versions, previousRoute() after client-side Inertia navigation. Existing non-navigation requests keep their current behavior.

Validation

  • Added five middleware regression tests covering a real Inertia visit and the AJAX, prefetch, precognitive, and non-GET boundaries.
  • Confirmed the main regression test fails on the current 3.x implementation before the fix.
  • Laravel 11.55: 413 tests, 1,513 assertions.
  • Laravel 12.64: 413 tests, 1,513 assertions; full PHPStan passes.
  • Laravel 13.21: 413 tests, 1,513 assertions.
  • Pint and PHPStan pass for all changed files across the tested framework versions.
  • composer validate --strict and composer audit pass with current dependencies.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

previousUri and previousRoute not set on Inertia route visit

1 participant