简体   繁体   English

Laravel route() 为本地主机返回错误的 url

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM