Home > Net >  Laravel Inertia Vue.js Duplicates App_URL into url
Laravel Inertia Vue.js Duplicates App_URL into url

Time:03-04

I have been working on a Laravel 8 Inertia and Vue.js project for a couple of weeks without this problem. My files were residing in C:\Users[my_user]\laravel. I was using the artisan command serve where it was opening 127.0.0.1:8080 as the local development server -- everything was fine. I decided that it was time to transfer the files to apache's http://localhost/laravel where I would use xampp to open the project instead of Laravel php artisan command serve. I have inspected my routes, Controllers, passed the Inertia::render() command, reached app.js without any problem. but when I run the createInertiaApp() I get url part being duplicated I guess by Inertia and not vue.js Here is the code I am having in my app.js

console.log('Still working well without duplicating url')

createInertiaApp({
title: (title) => `${title} - ${appName}`,
resolve: (name) => require(`./Pages/${name}.vue`),
setup({ el, app, props, plugin }) {
    return createApp({ render: () => h(app, props) })
        .use(plugin)
        .component('Link', Link)
        .component('Head', Head)
        .mixin({ methods: { route } })
        .mount(el);
},
});

NB: when I comment the createInertiaApp code, the home url will be perfectly http://localhost/laravel, but when I run the createInertiaApp I get http://localhost/laravel/laravel/

CodePudding user response:

I'm facing the same problem. I'm using Nginx, Laravel Jetstream with Inertia stack and I'm working on a local environment. What I get when I request a url e.g. 192.168.1.204:5500/helpdesk/public/login is 192.168.1.204:5500/helpdesk/public/helpdesk/public/login. Urls appear normal when I use php artisan serve. What I have noticed is that the issue lies on /vendor/inertiajs/inertia-laravel/src/Response.php toResponse() method and in particular in the following piece of code:

$page = [
        'component' => $this->component,
        'props' => $props,
        //'url' => $request->getBaseUrl().$request->getRequestUri(),
        'url' => $request->getRequestUri(),
        'version' => $this->version,
    ];

If you replace $request->getBaseUrl().$request->getRequestUri() with $request->getRequestUri() the problem should go away. But I think there must be a much better/cleaner way to do that. I hope someone else can provide more help on that.

Actually the above code was changed when support to Laravel 9 was added to inertia/laravel: https://github.com/inertiajs/inertia-laravel/pull/347/commits/bf059248ab73bcaccbea057d0a9fa11446fa0e20.

There is also an issue opened for this: https://github.com/inertiajs/inertia-laravel/pull/360.

  • Related