Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aminbaig's avatar

Jumping to an anchor tag in routes

I have home page with the section

  <section id="features" class="container services">

In my navigation I have the following link:

  <li><a class="page-scroll" href="#features">Features</a></li>

When I click on the link while I am on the home page it scrolls down to the relevant section, but since my navigation is in a partial, when I am on some other page and click on the link it does not take me back to home and the specified section.

My question is: How would I modify this link

{{route('home')}} 

to include the section id. Thanks in advance

0 likes
4 replies
edoc's avatar

Edit: You can create a fragment identifier like this route('home') . '#id'

1 like
aminbaig's avatar

Thanks edoc.....much appreciate it. It seems like this is the way to go but I am still trying to find anything more as this seems a bit tedious approach.

muzafferdede's avatar

Hi, how about put full link in href so if you are in homepage it's doesnt reload the page, If you are outside of homepage, it will bring you to home page first then hash tag.

<a href="your domain.com/home/#features">Features</a>

<a href="{{route('home')}}/#features">Features</a>
Rogercbe's avatar

You can always create a new helper function to do that, for example:


function fragment($route, $fragment) {
    return route($route) . "/#{$fragment}";
}
1 like

Please or to participate in this conversation.