Use already existing InertiaController as an API replacement #2199
thoresuenert
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Yesterday, i played around with the new
preserveUrlfeature. I developed the idea to use other inertia routes as endpoints for search selects or dialogs to filter and search data.In one of my projects i have a
form/show routewhere I add the relationshipscustomeranddocumentsto filter and search.To populate the data for my form i have the following Controller:
In another part of the application I also have these
IndexControllersfor both relationships:Now I got the following Idea:
/documentsand/customerswhere i already implemented all search functionality (the IndexControllers above)select popoverordialog, I dont need to store the data in the url for hard reloadsTo achieve this behavior I need to load the data as follows:
I updated the index endpoint as seen here:
Now instead of loading data from the inertia
show/pagewe get the data from thedocuments/index/page.When we trigger a partial request we load the component from the header, otherwise the default view is rendered[1]
/documentstheX-Inertia-Partial-Componentis set todocuments/index/pageand everything works fineX-Inertia-Partial-Componentis set toshow/pageand we stay on the current page with the current componentWhat do you think about this idea/approach to re use an existing endpoint as an api endpoint for async components like searchable select?
Further work to do:
Find a way to intially load the data. There are multiple options:
reloaduseEffectto trigger the async load when the component is rendering on the page[1] Background:
This approach only works because the inertia router checks if the payload component is the same as the current component and stays on the same page.
Every inertia request has the following header
X-Inertia-Partial-Componentwhich is the current page component.Beta Was this translation helpful? Give feedback.
All reactions