简体   繁体   English

如何将值从 controller 传递给 url?

[英]How to pass value to url from controller?

I have a single page website where all the information are loaded in single page.我有一个单页网站,所有信息都加载在单页中。 All my website sections are divided by id.我所有的网站部分都按 id 划分。 For example例如

<section id="banner">
</section>
<section id="aboutus">
</section>
    

Suppose when I load page, I want it to take me in about us section automatically.假设当我加载页面时,我希望它自动带我进入关于我们的部分。 I have tried by writing 127.0.0.1:8000/#aboutus in address bar manually and it worked.我已经尝试在地址栏中手动写入 127.0.0.1:8000/#aboutus 并且它有效。 Now from controller I want to pass #aboutus in url.现在从 controller 我想在 url 中传递#aboutus。

How can i achieve that?我怎样才能做到这一点? In my controller在我的 controller

public function index()
{   
   return view('landingpage');
}

How to put #abouts in url from controller?如何将#abouts 从 controller 放入#abouts中?

You can do this simply with anchor ( <a> ) tags within your view您可以简单地使用视图中的锚 ( <a> ) 标记来执行此操作

<li>
    <a href="#aboutus">About Us</a>
<li/>

No javascript is required.不需要 javascript。


If you want to append the hash to the url on load, this answer may be of use如果您想加载 append hash 到 url ,这个答案可能有用

Laravel - How to redirect with hash (#) Laravel - 如何使用 hash 重定向 (#)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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