Last active
August 31, 2023 07:04
-
-
Save Mattnmoore/195645dda6226ff5bb9ce6a094b9c440 to your computer and use it in GitHub Desktop.
Angular Skip Link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="skip-link"> | |
<a [href]="skipLinkPath">Skip to content</a> | |
</div> | |
<main id="main-content" class="content"> | |
<!--Main content goes here--> | |
</main> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in constructor or ngOnInit() | |
router.events.pipe(filter(event => event instanceof NavigationEnd)).subscribe(() => { | |
if( ! this.router.url.endsWith('#main-content')) { | |
this.skipLinkPath = `${this.router.url}#main-content`; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment