laravel - 加载和重新加载时根目录在 URL 中显示两次

标签 laravel url inertiajs laravel-jetstream

我正在尝试使用 Laravel 与 Jetstream 和 Inertia + Vue.js 构建一个应用程序。

网址如下所示:https://website/app/route

当我第一次访问该页面时,它会加载并且 URL 更改为:https://website/app/app/route。页面正确显示其内容。

如果我重新加载,我会收到 404 消息。我必须删除一个“/app”才能再次以正确的方式显示内容。

如果我不重新加载,我可以毫无问题地在页面上导航。

有人有想法吗?

.htaccess:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

我尝试从 APP_URL 和 ASSET_URL 中删除/app,但没有发生任何变化

APP_URL=https://website/app
ASSET_URL=https://website/app

最佳答案

答案如下:

在vendor/inertiajs/src/Response.php中的toResponse()方法中,URL是这样构建的:

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

我覆盖了这个文件并将其更改为:

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

关于laravel - 加载和重新加载时根目录在 URL 中显示两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71943581/

相关文章:

android - 为什么我的 WebView 以纯文本 HTML 形式显示 rss?

laravel - 如何在我的项目中设置惯性,当我尝试加载登录页面时出现错误

database - Laravel 队列、Beanstalkd 与数据库,有什么区别?

Laravel 经过身份验证的动态子域路由

.htaccess - 子域、丢失流量和 HTTPS 的动态 htaccess 处理

Android 使用其 URL 检查文件是否存在于远程服务器中

laravel - 混合内容 : The page at 'domain' was loaded over HTTPS, 但请求了不安全的 XMLHttpRequest 端点

laravel - 使用 Vue 3 在 InertiaJS 中定义全局组件

php - Laravel:向 1000 多个用户发送通知

php - withCount 闭包中的 groupBy (Laravel 5.3.26)