Within my AngularJS application, I have an about page that contains various sub-sections, all within the same template. My goal is to have each section accessible through its own unique URL that will automatically scroll down to the corresponding section if a match is found.
To achieve this, I have set up the states as follows:
.state('about', {
url: "/about",
templateUrl: "partials/about.html",
})
.state('about.team', {
url: "/about/team",
templateUrl: "partials/about.html"
})
.state('about.office', {
url: "/about/office",
templateUrl: "partials/about.html"
})
.state('about.other', {
url: "/about/other",
templateUrl: "partials/about.html"
});
On the about page, there is a fixed menu with links like:
<div class="menu">
<a ui-sref-active="selected"
ui-sref="about.team">The Team</a>
<a ui-sref-active="selected"
ui-sref="about.office">The Office</a>
<a ui-sref-active="selected"
ui-sref="about.other">Other</a>
</div>
This menu should enable users to navigate directly to specific sections by clicking on the links or entering the URLs in the address bar, triggering automatic scrolling to the desired section while updating the URL accordingly.
However, I am unsure of how to implement this functionality in Angular. To summarize:
- How can I achieve section scrolling based on the URL without using hash symbols due to compatibility issues and preference for HTML5 mode? Additionally, how can I trigger the scrolling after the initial app load?
- How can I ensure that clicking on the menu buttons not only updates the URL but also scrolls to the corresponding section on the page?
For reference, here is the HTML structure of the page: http://pastebin.com/Q60FWtL7
You can view the live app here:
An example of similar functionality can be seen here: , where the page automatically scrolls to the correct section based on the URL without using hash symbols.