将锚点添加到 Laravel 重定向回来

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39839737/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 14:33:18  来源:igfitidea点击:

Add an anchor to Laravel redirect back

phplaravelredirect

提问by user32421

In a Laravel controller I have this redirect:

在 Laravel 控制器中,我有这个重定向:

    return redirect()->back();

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.

这使我返回到上一页(比如http://domain/page)。但是,我想让页面跳转到特定的锚点(比如 #section)。所以最终应该打开这个页面:http://domain/page#section。我怎样才能做到这一点?我尝试将锚附加到重定向,但这不起作用。

回答by FluxCoder

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

And remember to import it at the top:

并记住在顶部导入它:

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

I hope this works for you!

我希望这对你有用!

回答by user3180582

You can use these helpers for laravel 5.5 and above - no imports :-)

您可以将这些帮助程序用于 Laravel 5.5 及更高版本 - 无导入 :-)

return redirect()->to(url()->previous() . '#hash');