fel*_*kpt 4 inertiajs laravel vue.js
我已经在 Laravel 8 Inertia 和 Vue.js 项目上工作了几周,没有遇到这个问题。我的文件位于 C:\Users[my_user]\laravel 中。我使用 artisan 命令服务,它打开 127.0.0.1:8080 作为本地开发服务器——一切都很好。我决定是时候将文件传输到 apache 的 http://localhost/laravel,在那里我将使用 xampp 打开项目而不是 Laravel php artisan 命令服务。我已经检查了我的路线、控制器,通过了 Inertia::render() 命令,到达了 app.js,没有任何问题。但是当我运行 createInertiaApp() 时,我发现 url 部分被重复,我猜是 Inertia 而不是 vue.js 这是我在 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);
},
});
Run Code Online (Sandbox Code Playgroud)
注意:当我评论 createInertiaApp 代码时,主页 URL 将完美地为 http://localhost/laravel,但是当我运行 createInertiaApp 时,我得到 http://localhost/laravel/laravel/
kav*_*ian 10
我面临着同样的问题。我正在使用 Nginx、Laravel Jetstream 和 Inertia 堆栈,并且我正在本地环境中工作。当我请求一个网址(例如192.168.1.204:5500/helpdesk/public/login)时,我得到的是192.168.1.204:5500/helpdesk/public/helpdesk/public/login。当我使用 php artisanserve 时,网址显示正常。我注意到问题在于 /vendor/inertiajs/inertia-laravel/src/Response.phptoResponse()方法,特别是以下代码片段:
$page = [
'component' => $this->component,
'props' => $props,
//'url' => $request->getBaseUrl().$request->getRequestUri(),
'url' => $request->getRequestUri(),
'version' => $this->version,
];
Run Code Online (Sandbox Code Playgroud)
如果更换的话$request->getBaseUrl().$request->getRequestUri()问题$request->getRequestUri()应该就会消失。但我认为必须有一种更好/更干净的方法来做到这一点。我希望其他人可以在这方面提供更多帮助。
实际上,当对Laravel 9的支持添加到inertia/laravel时,上面的代码被更改:https://github.com/inertiajs/inertia-laravel/pull/347/commits/bf059248ab73bcaccbea057d0a9fa11446fa0e20。
为此还提出了一个问题: https: //github.com/inertiajs/inertia-laravel/pull/360。