I am using the demo app PingCRM to learn how Inertia.js works.
When a user clicks on a main menu item, such as Organizations or Contacts, an XHR is sent to the corresponding URL, either /organizations
or /contacts
, as expected. If I use the pagination links at the bottom of a page, they send requests such as /contacts?page=1
, /contacts?page=2
, as expected.
If I navigate away from that section though, then navigate back, somehow the server knows which page I was up to and it returns a redirect. For example, if I am browsing /contacts?page=3
, then I select the main menu item Organizations, it requests /organizations
(as expected). When I next select Contacts however, it sends a /contacts
(as expected), but receives a 302 with the location set to /contacts?page=3
.
How does this feature work? Is the Laravel session storing my state, and is this part of the Inertia back end adapter? Or is the state stored in the browser and passed to the server in a cookie? Where can I find details of this in the Intertia.js documentation? (The section on Local State seems to relate more to browser history).
I notice that a similar scenario exists when you filter organizations. If you navigate away from the page while a filter is in use, then return to the page, a request to /organizations
received a 302, with a location of /organizations?search=abc
.
Found the answer...
These routes have a middleware attached which 'remembers' the query string. When a request comes in to one of these routes, if it does not have a query string and one was previously 'remembered', it is added to the route and a redirect is sent to the client.
The code is in the class
Reinink\RememberQueryStrings