From b067b373fdc31d0dee74cd301b208c7cb319696d Mon Sep 17 00:00:00 2001 From: Stefan Hauke Date: Mon, 13 Jan 2020 18:40:36 +0100 Subject: [PATCH] feat: add anchor scrolling / fragment navigation on the current route for serverHtml content (#80) --- src/app/core/directives/server-html.directive.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/app/core/directives/server-html.directive.ts b/src/app/core/directives/server-html.directive.ts index 5edee08766..369457e3f0 100644 --- a/src/app/core/directives/server-html.directive.ts +++ b/src/app/core/directives/server-html.directive.ts @@ -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. 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);