将锚添加到Laravel重定向回

问题描述:

在Laravel控制器中,我具有以下重定向:

In a Laravel controller I have this redirect:

    return redirect()->back();

这使我回到上一页(例如 http://domain/page ).但是,我想使页面跳转到特定锚点(例如#section).因此,最终应打开此页面: http://domain/page#section .我怎样才能做到这一点?我尝试将锚添加到重定向,但这不起作用.

Which returns me to my previous page (say http://domain/page). However, I want to make the page jump to a particular anchor (say #section). So ultimately this page should be opened: http://domain/page#section. How can I make this happen? I tried appending the anchor to the redirect but that doesn't work.

return Redirect::to(URL::previous() . "#whatever");

并记住将其导入顶部:

use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\URL;

我希望这对您有用!