question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Anchor link outside of Angular App refresh the page (skip to content link)

See original GitHub issue

🐞 bug report

Affected Package

This issue might be caused by the @angular/router module.

Is this a regression?

It is probably not a regression regarding this similar issue talking about Angular 2 : https://github.com/angular/angular/issues/13622

Description

Hello, In my application I have a skip to content link for accessibility improvement. This link is created by an external script, and therefore is not inside my Angular App.

The skip link is just an HTML link with href="#anchor" and an element having the corresponding id in the DOM.

If I click on the skip link, on the “/” route, it works as intended. But if the path is not empty, the link seems to refresh the page to the root path and doesn’t go to the anchor.

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-outside-anchor

1 - Click on the “Go to test route” to navigate to a /test path (you should see the component in the router-outlet) 2 - Click on the “Go to the anchor” link 3 - We can see the /test#anchor in the address bar, but it redirect instantly to /#anchor 4 - I’m not on the route I was and i didn’t get to the anchored (can i say that ?) element.

🌍 Your Environment

Angular Version: Angular 10, Angular 9

Notes

There is an onclick approach, as suggested in this SO response : https://stackoverflow.com/questions/50836497/using-html-anchor-link-id-in-angular-6 but I think the standard link approach without onclick event should work as intended.

The anchorScrolling: "enabled" option on the RouterModule doesn’t change anything.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
meriturvacommented, Jul 10, 2020
0reactions
angular-automatic-lock-bot[bot]commented, Aug 10, 2020

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Page reloads when clicking anchor element - Stack Overflow
Strangely when I open dev tools in Chrome, choose the network tab and select disable cache the page only refreshes the first time...
Read more >
A Quick Note on Skip-Links in Angular | by Stephen Belyea
For reference, a “skip-link” is a visually-hidden anchor element used to skip repetitive blocks (eg. main navigation) throughout a website.
Read more >
How to Create a “Skip to Content” Link - CSS-Tricks
It offers a “Skip to content” button that allows users to skip all the navigation items and jump straight to the main content....
Read more >
RouterLink - Angular
When applied to an element in a template, makes that element a link that initiates navigation to a route. Navigation opens one or...
Read more >
Empty href attribute navigates to the app base #7294 - GitHub
I am looking to have an element act as a link with the mouse responding to the hover element and I am getting...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found