Skip to content

Commit 29715e6

Browse files
devversionjelbourn
authored andcommittedDec 15, 2017
fix: external links with hash are updated incorrectly (#355)
External links with a hash are incorrectly updated, because they are considered as hash links that are referring to a local anchor on the current page (fragment links).
1 parent 48da871 commit 29715e6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed
 

‎material.angular.io/src/app/shared/doc-viewer/doc-viewer.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ export class DocViewer implements OnDestroy {
115115
const anchorElements =
116116
[].slice.call(this._elementRef.nativeElement.querySelectorAll('a')) as HTMLAnchorElement[];
117117

118+
// Update hash links that are referring to the same page and host. Links that are referring
119+
// to a different destination shouldn't be updated. For example the Google Fonts URL.
118120
anchorElements
119-
.filter(anchorEl => anchorEl.hash)
121+
.filter(anchorEl => anchorEl.hash && anchorEl.host === location.host)
120122
.forEach(anchorEl => anchorEl.href = `${baseUrl}${anchorEl.hash}`);
121123
}
122124

0 commit comments

Comments
 (0)
Please sign in to comment.