【问题标题】:Laravel routes doesn't work other than '/' after change AllowOverride更改 AllowOverride 后,Laravel 路由除了 '/' 之外不起作用
【发布时间】:2020-12-04 09:33:25
【问题描述】:

在我使用 laravel 7.25 创建项目后(这是我第一次使用这个版本,我在最后一个项目中使用了 7.20)我在路由文件夹的 web.php 文件中创建路由

Route::get('/', function () {
     return view('welcome');
});
Route::get('/test', function () {
    dd("k");
});

当我尝试运行它们时,只有“/”有效,而“/test”未找到 404,但它可以在我朋友的设备上运行,我使用 xampp,这是 apache httpd.conf:

DocumentRoot "C:/xampp/htdocs"
<Directory "C:/xampp/htdocs">
    AllowOverride All
    Require all granted
</Directory>

【问题讨论】:

  • 为什么第二条路线不起作用?是有错误还是什么?请提供更多信息...
  • 哦,是的,对不起,它只显示未找到 404
  • 当你在控制台运行php artisan route:list时,有/test路由吗?
  • 是的,动作是关闭

标签: laravel xampp


【解决方案1】:

根据我们在 cmets 中的对话,我认为问题在于您的路由函数没有 return 值,因此它返回空页面或 404。尝试将您的路线更改为:

Route::get('/test', function () {
    return dd("k");
});

official documentation 上阅读更多关于路线的信息,

【讨论】:

  • 嗯,不知道可能是什么问题。这两个是您在路由文件中定义的唯一路由吗?
  • 不,他们在这里:Route::get('/schedule', 'ControllerSchedule@index')-&gt;name('indexschedule'); Route::get('/', function () { return view('welcome'); }); Route::get('/test', function () { return dd("k"); }); Auth::routes(); Route::get('/home', 'HomeController@index')-&gt;name('home');
猜你喜欢
  • 2014-03-25
  • 2015-12-13
  • 2015-04-25
  • 1970-01-01
  • 2017-02-24
  • 2016-04-04
  • 2013-02-28
  • 2022-06-24
  • 2014-07-31
相关资源
最近更新 更多