1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

URL gets appended with /test/ twice when using Inertia.js with Laravel

Discussão em 'Outras Linguagens' iniciado por Vojtěch Košárek, Setembro 10, 2024.

  1. I'm experiencing an issue with Laravel and Inertia.js where the URL is being appended with /test/ twice when rendering a page. My project is hosted at https://something.com/test/, but when attempting to view the login/register page, the URL changes to https://something.com/test/test/login, which causes redirection issues and 404 errors.

    Here’s the relevant code:

    1. Laravel Route and Controller:

    // routes/web.php
    Route::get('/login', [AuthenticatedSessionController::class, 'create'])->name('login');

    // app/Http/Controllers/Auth/AuthenticatedSessionController.php
    public function create(): Response
    {

    // if I place dd('something'); here, the url is okay, it doesn't add another /test/, so I think problem will be with Inertia render

    return Inertia::render('Auth/Login', [
    'canResetPassword' => Route::has('password.request'),
    'status' => session('status'),
    ]);
    }

    1. App.js Configuration:

    createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
    setup({ el, App, props, plugin }) {
    return createApp({ render: () => h(App, props) })
    .use(plugin)
    .use(ZiggyVue)
    .mount(el);
    },
    progress: {
    color: '#126afb',
    },
    });

    1. .env Configuration:

    APP_URL=https://something.com/test
    ASSET_URL=https://something.com/test

    1. .htaccess Configuration:

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
    RewriteBase /test/
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /test/index.php [L]
    </IfModule>


    Does anyone have any idea why this might be happening or how to fix it?

    tried configuring the Laravel Inertia.js and Vue components for rendering the login page without appending extra segments to the URL. Specifically, I:

    Checked and adjusted the Inertia.js setup to ensure correct routing.

    • Verified the Vue component configuration to ensure no URL manipulation was occurring within the client-side code.
    • Examined the .env and .htaccess configurations for potential URL base path issues.
    • I expected the URL to remain consistent at https://something.com/test/login when rendering the login page.

    However, the actual result was that the URL incorrectly changed to https://something.com/test/test/login, leading to a redirection issue and resulting in a 404 error when refreshing the page.

    Does anyone have any idea why this might be happening or how to fix it?

    Thank you in advance!

    Continue reading...

Compartilhe esta Página