为什么 laravel 着陆页路由 return MethodNotAllowedHttpException?

Why laravel landing page route return MethodNotAllowedHttpException?

我正在使用 laravel 7.x。 因为 function(){return view(welcome);} 当我 运行 php artisan route:cache 时会产生错误,所以我在下面写这段代码来替换 function():

Route::get('/', 'WelcomeController@index')->name('welcome');

它运行 很好php artisan serve 命令。 但是当我直接从 public 文件夹 运行 时,它会产生异常 MethodNotAllowedHttpException。我找不到它发生的原因,你能帮我看看它发生的原因吗?

异常信息:

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: HEAD.
https://localhost/laravel-tester/public/ 

欢迎控制器方法

public function index(){
   return view('welcome');
}

::get 默认为方法 GET 和 HEAD 注册路由。您正在尝试使用 GET 请求访问它(正如您应该的那样),但它没有 return 它。可能是你的 Router class 有问题,所以请对照下面评论中的方法检查你的 Routing\Router.php class。