【发布时间】:2020-09-24 03:45:11
【问题描述】:
所以我不知道为什么 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 中。有没有办法配置 browser-sync 或 laravel 以返回正确的路由?
P/S : 作为附加信息,即使路由生成为//localhost:3010/home laravel 仍然设法将其重定向到正确的页面。但是当我尝试在 JS 中创建 new URL('//localhost:3010/home') 时,它返回为无效 URL。
任何帮助都会很棒。谢谢
【问题讨论】:
-
而不是指定
route('home/index')给它一个名字并在路由中使用 -
请提供路由文件代码和问题相关代码,以便识别问题。
-
正如@AnkitJindal 所暗示的那样,您可能希望像
Route::get('home/index', "SomeController@someAction")->name('home');这样定义您的路线,然后调用route('home')或使用url('home/index') -
我确实以 @WesleySmith 的方式定义了路线
-
酷,但你打电话给
route('home/index');而不是route('home')
标签: php laravel routes browser-sync