[英]Laravel route() returns wrong url for localhost
So I'm at lost as to why laravel's global function route()
generate a wrong URL when used in localhost.所以我不知道为什么 laravel 的全局函数
route()
在 localhost 中使用时会生成错误的 URL。
I used it like so route('home:index');
我像这样使用它
route('home:index');
and the generated route is //localhost:3010/home
instead of https://localhost:3010/home
生成的路由是
//localhost:3010/home
而不是https://localhost:3010/home
I tested both URL in browser and only 2nd one works.我在浏览器中测试了两个 URL,只有第二个有效。 The firs one shows
Your File Was Not Found
error page.第一个显示
Your File Was Not Found
错误页面。
I define the route as follows:我定义的路线如下:
Route::group(['as' => 'home:', 'prefix' => 'home', 'namespace' => 'Home'], function () {
Route::get('/', ['as' => 'index', 'uses' => 'HomeController@index']);
// other routes here.
});
After further investigation, this only happens in localhost when I use browser-sync.经过进一步调查,当我使用浏览器同步时,这只发生在本地主机中。 Is there a way to configure browser-sync or laravel to return correct route?
有没有办法配置浏览器同步或 Laravel 以返回正确的路由?
P/S : As additional info, even with route generated as //localhost:3010/home
laravel still manage to redirect it to the right page. P/S :作为附加信息,即使路由生成为
//localhost:3010/home
laravel 仍然设法将其重定向到正确的页面。 But when I tried creating new URL('//localhost:3010/home')
in JS it returned as invalid URL.但是当我尝试在 JS 中创建
new URL('//localhost:3010/home')
,它返回为无效的 URL。
Any help would be great.任何帮助都会很棒。 Thanks
谢谢
Route::group(['as' => 'home:', 'prefix' => 'home', 'namespace' => 'Home'], function () {
Route::get('/', ['as' => 'index', 'uses' => 'HomeController@index']);
// other routes here.
});
Use above route as route('index')
or else use it as url('/')
将上面的路由用作
route('index')
或将其用作url('/')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.