首页 > 解决方案 > Laravel route() 为 localhost 返回错误的 url

问题描述

所以我不知道为什么 laravel 的全局函数route()在 localhost 中使用时会生成错误的 URL。

我像这样使用它route('home:index');,生成的路线//localhost:3010/home不是https://localhost:3010/home

我在浏览器中测试了两个 URL,只有第二个有效。第一个显示Your File Was Not Found错误页面。

我将路线定义如下:

Route::group(['as' => 'home:', 'prefix' => 'home', 'namespace' => 'Home'], function () {
    Route::get('/', ['as' => 'index', 'uses' => 'HomeController@index']);
    // other routes here.
});

经过进一步调查,当我使用浏览器同步时,这只发生在 localhost 中。有没有办法配置浏览器同步或 laravel 以返回正确的路由?

P/S:作为附加信息,即使生成为//localhost:3010/homelaravel 的路由仍然设法将其重定向到正确的页面。但是当我尝试new URL('//localhost:3010/home')在 JS 中创建时,它返回为无效的 URL。

任何帮助都会很棒。谢谢

标签: phplaravelroutesbrowser-sync

解决方案


Route::group(['as' => 'home:', 'prefix' => 'home', 'namespace' => 'Home'], function () {
    Route::get('/', ['as' => 'index', 'uses' => 'HomeController@index']);
    // other routes here.
});

将上述路线用作route('index')或将其用作url('/')


推荐阅读