【发布时间】:2023-01-04 13:55:04
【问题描述】:
我有一个 Laravel 项目以及 Inertia.js 和 React.js。它在我的开发机器(又名本地主机)中运行良好。但是当我将它部署到虚拟专用服务器中的 Apache 服务器时出现问题
当我点击 /login 端点时,它返回 Uncaught Error: Ziggy error: route '/login' is not in the route list.
我已经将 .env 中的 APP_URL 更改为我使用的域。 这是我在项目中使用的依赖项
"dependencies": {
"@draft-js-plugins/static-toolbar": "^4.1.2",
"@fortawesome/fontawesome-free": "5.15.3",
"@popperjs/core": "2.9.1",
"@tailwindcss/forms": "0.2.1",
"autoprefixer": "10.2.5",
"babel-plugin-macros": "^3.1.0",
"chart.js": "^3.9.1",
"draft-js": "^0.11.7",
"gulp": "4.0.2",
"gulp-append-prepend": "1.0.8",
"js-file-download": "^0.4.12",
"moment": "^2.29.1",
"numeral": "^2.0.6",
"postcss": "8.2.8",
"quill-image-resize-module-react": "^3.0.0",
"react": "17.0.1",
"react-alert": "^7.0.3",
"react-alert-template-basic": "^1.0.2",
"react-chartjs-2": "^4.3.1",
"react-dom": "17.0.1",
"react-google-recaptcha": "^2.1.0",
"react-js-pagination": "^3.0.3",
"react-moment": "^1.1.1",
"react-pluralize": "^1.6.3",
"react-quill": "^2.0.0-beta.4",
"react-recaptcha": "^2.3.10",
"react-router": "5.2.0",
"react-router-dom": "5.2.0",
"react-scripts": "4.0.3",
"react-select": "^5.0.0",
"slate": "^0.66.1",
"slate-react": "^0.66.1"
}
这是我与登录端点相关的路由文件
Auth::routes(['verify' => true]);
Route::middleware('guest')->group(function () {
Route::get('/login', [AuthenticatedSessionController::class, 'create'])->name('login');
Route::post('/login', [AuthenticatedSessionController::class, 'store'])->name('login');
});
这就是我在 react.js 上调用登录端点的方式
const submit = (e) => {
e.preventDefault();
if(!data.CaptchaCode){
alert('Invalid captcha!')
return
}
post(route('/login'));
recaptchaRef.current.reset();
}
如果需要,这是 /etc/apache2/sites-available/laravel-project.conf 中的 Apache 配置
<VirtualHost *:80>
ServerName mydomain.com
ServerAdmin webmaster@thedomain.com
DocumentRoot /var/www/project-folder/public
<Directory /var/www/project-folder>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
预先感谢您的帮助!
【问题讨论】:
-
您使用
route name而不是path。在你的情况下login没有'/',你也有一条相同的路线name你应该改变另一个像login.auth
标签: reactjs laravel apache inertiajs ziggy