diff --git a/src/util/relative-to-root-links.js b/src/util/relative-to-root-links.js index ee33c5e8..7729c7ed 100644 --- a/src/util/relative-to-root-links.js +++ b/src/util/relative-to-root-links.js @@ -19,6 +19,11 @@ function removeTrailingIndex(path) { * /addons remains untouched */ function relativeToRootLinks(href, path = '', isIndexPage) { + if (!href) { + // Accomodating `` + return href; + } + const relativeUrlRegex = /^(?!\.\.\/\.\.\/)(\.\/)(.*)$/; const multiLevelRelativeUrlRegex = /^(?!\.\.\/\.\.\/)(\.\.\/)(.*)$/; diff --git a/src/util/relative-to-root-links.test.ts b/src/util/relative-to-root-links.test.ts index 32a6a693..0d2614ec 100644 --- a/src/util/relative-to-root-links.test.ts +++ b/src/util/relative-to-root-links.test.ts @@ -45,3 +45,8 @@ it('does not transform non-relative links', () => { const rootUrl = relativeToRootLinks('/foo', '/docs/writing-stories/args'); expect(rootUrl).toEqual('/foo'); }); + +it('does nothing to named anchors', () => { + const rootUrl = relativeToRootLinks(); + expect(rootUrl).toBeUndefined(); +});