Community forum for knowledge and support

Updated 9 months ago

Handling Navigation Links Across Multiple Pages

At a glance

The community member is having issues with their navigation bar. The nav links scroll to sections on the home page, but this causes problems when they have separate pages. They tried using a URL with /#[section-id], which worked except for the mobile nav menu - the menu doesn't close when clicking a link. Another attempt was to unlink the nav component on the home page and create a duplicate nav link, but this changed the nav bar component links on the other pages.

In the comments, another community member suggests creating a component out of the list of links and maintaining two separate components, but notes it's messy. Another community member fixed the menu closing issue by changing the navbar to 'fixed' and adding an empty div, but this caused a new issue where the top of the section gets cut off when navigating from other pages.

The final comment provides a solution: create an empty div that holds the ID for each section, and offset it above the actual section by the height of the navbar. This allows the sections to be properly displayed when navigating from other pages.

Hi,

I’m having an issue with my nav bar. All my nav links scroll to a section on the home page. I set each link to scroll to that section of the page which works. But I have a couple of separate pages and this causes an issue.

I tried to get around this by setting the link to a URL with /#[section-id]. This also works except with the mobile nav menu. If I am on the home page in mobile view (hamburger menu), and I click on a link, it scrolls to the section but the nav menu doesn’t close.

I’ve also tried unlinking the nav component on the home page and creating a duplicate nav link with a new class name but for some reason this changes the nav bar component links on the other pages too.

M
S
4 comments

ive had this issue, i would create a component out of the list of links and maintain two separate components. Its messy. You might be able to find some JS way but I dont know how.

Wow, quite messy but it did fix the menu closing issue. There is another issue though - because my navbar is sticky, when it scrolls to the section, the top part of that section is cut off (it gets more cut off the smaller the viewport is).
I changed it to 'fixed' and added an empty div to give the hero some space. This works except when navigating to that section from the other pages (top part gets cut off again).
Any ideas?

yeah, these are all workarounds from years-old webflow bugs unfortunately.

My way around this is to create an empty div that holds the ID for that section, and offset it above the actual section the same height as your navbar.

So within each section_ you'll have lets say a section_anchor - give it the unique ID of that section. Then give a position absolute, width 100%, height the height of your navbar - most likely somewhere around 4.5rem. Then do a top position of -4.5rem (or whatever height your navbar is. Make sure to have position relative set on your section_ div.

Works perfectly now, thank you!

Add a reply
Sign up and join the conversation on Slack