inertiajs / inertia

Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
https://inertiajs.com
MIT License
6.52k stars 434 forks source link

Laravel + React + Breeze Url Twice time Issue #2088

Open ReactJsScc opened 2 days ago

ReactJsScc commented 2 days ago

Version: @inertiajs/react version: 1.0.0 Describe the problem: After setting up a Laravel + React + Breeze application, I’ve noticed that sometimes the URL in my browser renders incorrectly, showing /public/ twice. For example:

### http://localhost/Ravi/inventory-main/public/Ravi/inventory-main/public/ This happens intermittently and is causing issues with how my application loads.

Steps to reproduce: Set up a Laravel application with React and Breeze. Access the app in the browser using http://localhost/{project-folder}/i Occasionally, the URL will render incorrectly, showing /public/ twice, like in the example above.

kresnasatya commented 2 days ago

Hi, how do you setup this project? I'm curious because the url you open is http://localhost/{project-folder}. Usually, Laravel project include Laravel + Breeze + Inertia + React can be accessed in http://localhost:8000. By the way, the Laravel team give a great tutorial for programmer to be more familiar with Laravel framework.

The tutorial called Laravel Bootcamp: https://bootcamp.laravel.com/inertia/installation. Feel free to visit. It covers step by step how to create and run Laravel Project using Inertia + React stack.

I hope it helps.

ReactJsScc commented 2 days ago

While php artisan serve runs completely fine, when accessing the project through localhost via the XAMPP file directory, I am getting this issue

RobertBoes commented 2 days ago

If you're accessing your app through http://localhost/{project}/public, that's an incorrect hosting setup for a Laravel app. You should never access the /public directory. Instead, you'd use a document_root set to the public folder of your app. Nothing to do with Inertia, just that you wouldn't run a Laravel app that way.

kresnasatya commented 2 days ago

Yes, the behaviour of XAMPP it self is not suitable to run the Laravel project because of the structure the Laravel framework itself. Laravel store the core (index.php) inside the public directory. In short, it's tricky to use XAMPP for this case. I would suggest to use Laragon: https://laragon.org to run Laravel project.

Article: https://medium.com/@omobadesanya/installing-and-getting-laravel-working-on-windows-in-few-steps-using-laragon-ad74da0d1e37

benjivm commented 1 day ago

Laragon is not maintained and has myriad issues with both PHP extensions and the latest database binaries. Just use Herd and DBngin, non-Laravel projects are trivial to serve via Valet's drivers.

A proper vhost setup will resolve this issue.