1

I have a single page website where all the information are loaded in single page. All my website sections are divided by 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. Now from controller I want to pass #aboutus in url.

How can i achieve that? In my controller

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

How to put #abouts in url from controller?

zahid hasan emon
  • 6,023
  • 3
  • 16
  • 28
ram ram
  • 27
  • 5
  • do you want to redirect to about us page when u click on about us ,or do you want to make about us the default page? – Hirumina Jul 03 '20 at 11:36
  • you are returning a view, if you want a new url, you will have to either redirect to that url, or change it in the frontend with javascript https://stackoverflow.com/questions/824349/how-do-i-modify-the-url-without-reloading-the-page – MrEvers Jul 03 '20 at 11:36
  • `#` is the `id` off html element attribute – STA Jul 03 '20 at 11:37
  • @Hirumina In landing page there is aboutus section . I want to directly show to that page without scrolling – ram ram Jul 03 '20 at 11:37
  • @STA yes. i have placed
    . When i type #aboutus in url i get desired results but confused how can i do that from controller
    – ram ram Jul 03 '20 at 11:39
  • This is done in the frontend, not the backend. The backend only prints out your page, in the frontend you can manipulate things like scrolling to an id – MrEvers Jul 03 '20 at 11:44

1 Answers1

1

You can do this simply with anchor (<a>) tags within your view

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

No javascript is required.


If you want to append the hash to the url on load, this answer may be of use

Laravel - How to redirect with hash (#)

Spholt
  • 3,724
  • 1
  • 18
  • 29