-
-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Laravel Inertia apps doesn't support subdomain redirects #431
Comments
Solved the issue by making the below changes to cors.php
No cors issues now but I'm having a different issue where the desired page rendered by Inertia on the incorrect route. Raised the Issue for Laravel Framework |
This is driving me crazy! Subdomains isn't working even if I hard set the redirect like this redirect()->to('http://username.example.test/productSlug') it gives me in the browser url example.test/productSlug only. I even used Inertia to redirect from the frontend to a url and did the same. The only thing that works is using Inertia::location() but this causes a full page refresh. |
Same behavior occurs with Inertia's If you are on a subdomain route like |
Javascript's |
@MooseSaeed Hey I honestly don't think this is possible to make Inertia requests across subdomains — sorry! |
@reinink I agree! After days of research I'm sure now that it is impossible to route redirect to a subdomain route from root domain without page refresh. Any change to the host will require the page to reload which is out of Laravel and JetStream scope and out of InertiaJS hands. As far as I understand that this is for security purposes. Sorry for wasting your time and thanks a million for your efforts |
Yes inertia works with browser history, but it seems inertia is missing a check, so that redirects to a different domain are handled correctly and reload the page |
@MooseSaeed As a workaround you can add to your HandleInertiaRequests middleware public function version(Request $request): string
{
return md5($request->host) . parent::version($request);
} And if you have CORS working, the request will be followed and inertia will reload the page but you'll have one more request than what is strictly necessary Cross domains redirects are not very frequent so you'd be better doing it explicitely without inertia using a window.location and it would prevent all the CORS issues that goes with it If you need the domain to be dynamic, instead of a redirect then send the url as an inertia prop and use that in the success handler for your window.location |
@reinink sorry to bother, but question, that is not covered in docs/thread and related to current issue. Is using It's the same app, same cookie name, subdomains due to SEO-stuff. Cause I don't see any issues with that, but would like not to face any long-term. |
Just found this issue as i was having issues with the same thing, is there any chance sub domain redirects can be added to inertia? Would be a great help! |
Hey there, We're closing this issue because it's inactive, already solved, old or not relevant anymore. Feel to open up a new issue if you're still experiencing this problem. |
Just came across this issue and, like @riabiy-denis, I solved it via a small component that either outputs an |
I understand that inertia prevents cross-subdomain redirects for security purposes. But I'm having a similar issue right now. I have a landing page on example.test and an admin panel on crm.example.test This two layouts are completely different and don't redirect to each other. On the landing page, there's not a "go to admin panel" link or something like that. There's no link between subdomains. But still, I'm having the "pushState" error. I'm trying to redirect from crm.example.test/login to crm.example.test/dashboard and have pushState error. When I add replace:true option to router, redirect happens and dashboard page renders but still have the console error and url stands still as /login. Any ideas? |
@ibrahimdolas Don't think that has anything to do with this issue. You say you're not navigating between different (sub)domains, so there wouldn't be any conflict. Inertia only pushes the path to the history state (which also is the only thing that's allowed) so that in itself wouldn't trigger pushstate errors. |
I am using Laravel 11 and faced the same issue. // bootstrap/app.php
return Application::configure(basePath: dirname(__DIR__))
->withRouting(
commands: __DIR__.'/../routes/console.php',
health: '/up',
then: function () {
Route::domain(config('app.url'))
->middleware('web')
->group(base_path('routes/web.php'));
Route::domain(config('app.admin_url'))
->middleware(['web', 'auth'])
->name('admin.')
->group(base_path('routes/admin/web.php'));
}
)
... After authorization, I redirect to the admin panel. // app/Http/Controllers/Auth/AuthenticatedSessionController.php
public function store(LoginRequest $request)
{
$request->authenticate();
$request->session()->regenerate();
// return redirect()->intended(route('admin.test')); // don't work
return Inertia::location(route('admin.test')); // work
} |
I'm working on a Laravel 9, InertiaJS and vue project where a user can submit a new product through
products/create
route and this sends to ProductController@store which does all what it's supposed to do and then supposedly redirect the user to the newly created product on a subdomain route like thishttp://username.example.test/my-new-product
The issue I'm having is that I keep getting the below error and the redirect doesn't work:
The code works as follows:
1- The form:
2- Products create router:
3- The controller - Storing the new product with user details and redirecting (which doesn't work) to show the product
4- The show route and controller@show
I saw @reinink explain in this Issue that we can use now Inertia::location
The only way I could get this to work is returning this is the ProductController@store:
But It causes a full page refresh which defeats the whole concept of having a single page application and I will have to remember changing 'http' to 'https' and domain to the real domain when I'm going to put the app in production. I was hoping that I was doing something wrong but after hours of searching for a solution I began to think that Laravel Inertia apps doesn't support subdomain redirects
The text was updated successfully, but these errors were encountered: