2015-07-20 85 views
1

我正在使用下面的代码重定向到根页面。重定向时根网页不工作

return Redirect::to('/'); 

我已经定义了主页路由如下。

Route::get('/', '[email protected]'); 

当页面重定向到根页,我希望网址是http://localhost/crafts/public/但其http://localhost/crafts/public/home。我不确定那/ home是在哪里添加的。我有PagesController文件中定义的家庭功能。

这是PagesController部分。

public function home() 
{ 
    return view('home'); 
} 

下面显示的所有其他路线都能正常工作,除了主要路线。

Route::get('about', '[email protected]'); 
Route::get('contact', '[email protected]'); 
Route::get('auth/{provider}', 'Auth\[email protected]'); 
Route::get('auth/{provider}/callback', 'Auth\[email protected]'); 

请解释我做错了什么?

+0

请显示您的所有路线。 – user2094178

+0

编辑该问题以添加所有路线。 – Purus

+0

这很奇怪。我的猜测是'RedirectIfAuthenticated'中间件在你的重定向尝试之前开始。 – user2094178

回答

1

如果你看一下

app/http/Middleware/RedirectIfAuthenticated.php 

它有这样的代码:当您正在使用重定向

/** 
* Handle an incoming request. 
* 
* @param \Illuminate\Http\Request $request 
* @param \Closure $next 
* @return mixed 
*/ 
public function handle($request, Closure $next) 
{ 
    if ($this->auth->check()) { 
     return redirect('/home'); 
    } 

    return $next($request); 
} 

因此,它可能验证第一,然后调用句柄功能上面这显然增加了/ home

我注意到一件事,你说你在问题标签中使用Laravel-5。在这种情况下,替换重定向代码:

return redirect('/'); 

语法Redirect::To是版本4.x或更早。

+0

好..这个重定向(“/”)在控制器中到达哪里?我正在使用家庭控制器中的视图来呈现它。 – Purus

+0

'重定向()'是一个帮手 – user2094178