Closed Neophen closed 4 years ago
@Neophen , just want to share my experience.
I have a very similar setup, one app (with its own mix config, css, etc) to the public frontend and one for the admin frontend.
In some cases I also need to link a resource from the admin to the public frontend. For that I use regular anchor tags (<a href></a>
)
I am not a maintainer of inertia, but I guess this is intended behavior. By design after the first request, which knows which blade template to use and bootstrap the inertia app, all the next requests would respond with a JSON payload with the changes needed.
In the case you described, as the navigation is switching blade templates, it would need either way to bootstrap the new app all over again. Basically the same behavior you get with a regular anchor tag. For me it makes sense as it navigating trough two different apps, we could think of them as separated sites, in that case you would need to use a regular anchor tag either way.
I guess, if you want to use <InertiaLink />
you could circumvent it in the backend by responding with a 409 status code and a X-Inertia-Location
header. Similar to what Inertia already does when you have the assets versioning feature in place:
In the frontend if the response has that status code and header, inertia will hard redirect to the new location instead of trying to hydrate the app with the expected JSON response.
But, in my opinion this is more work, and also add one more check to each request, than just using a regular anchor tag when switching applications.
Hope it helps anyhow.
Yup makes sense. I wish this was supported out of the box. And awesome i've hacked together some things and now this looks amazeballs!
I had the same issue and solved it like this. Perhaps this helps someone else. https://gist.github.com/lukaskleinschmidt/714435e77e7b7a46f5960acaee54153a
Use case: My setup i'm building two completely different apps within the same laravel I have separate mix.js files and separate tailwind config files. and i use laravel-mix-manifest merge to merge all of the built stuff into one manifest.
Trying to use $inertia.visit to change the apps does not work. Since it tries to look for the page component in the previous app, eg:
The hack is to simply use a normal link or window.location.href The only thing is trying to catch all the way you can go from one app to the other is difficult.
I though that
Inertia::setRootView('tenant-admin.app');
would do the trick, but it does not as while it sets the root view ('checked in the Inertia core and logged it out) that doesn't mean anything to the visit request as it just gets a json response.Questions:
Any help is greatly appreciated.