Skip to content

Commit

Permalink
feat: add anchor scrolling / fragment navigation on the current route…
Browse files Browse the repository at this point in the history
… for serverHtml content (#80)
  • Loading branch information
shauke committed Jan 17, 2020
1 parent 1fcb795 commit b067b37
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/app/core/directives/server-html.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ export class ServerHtmlDirective implements AfterContentInit, AfterViewInit, OnD
}

if (cb && this.callbacks && typeof this.callbacks[cb] === 'function') {
// handle links with callback functions, e.g. <a callback="availableCallbackFunction">
this.callbacks[cb]();
} else if (href.startsWith('#')) {
// handle fragment links / anchor navigation
document.getElementById(href.replace('#', '')).scrollIntoView({ block: 'start', behavior: 'smooth' });
} else {
// otherwise handle as routerLink
this.router.navigateByUrl(href);
Expand Down

0 comments on commit b067b37

Please sign in to comment.