Skip to content

Commit 34b047c

Browse files
committed
docs: clean up compileMarkdown's link handler to strip leading / and # before navigateTo so markdown links produce clean URLs
1 parent ffdf4e3 commit 34b047c

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

packages/__docs__/src/compileMarkdown.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,17 @@ const renderer = (title: string) => ({
290290
// Markdown links can point to a specific version of a component,
291291
// e.g. href="/v11_7/DateInput". navigateTo() expects the page
292292
// name and version as separate arguments, so we need to split
293-
// them apart. Plain links like "DateInput" are passed through
294-
// as-is.
295-
const path = href.replace(/^\/+/, '') // "/v11_7/DateInput" -> "v11_7/DateInput"
293+
// them apart. Plain links like "DateInput", "/DateInput", and
294+
// legacy hash-routing links like "/#DateInput" are normalised
295+
// to the bare page name.
296+
const path = href.replace(/^\/+/, '').replace(/^#+/, '')
296297
const [first, second] = path.split('/')
297298
const isVersionedLink = MINOR_VERSION_REGEX.test(first) && second
298299

299300
if (isVersionedLink) {
300301
navigateTo(second, { minorVersion: first })
301302
} else {
302-
navigateTo(href)
303+
navigateTo(path || 'index')
303304
}
304305
}}
305306
>

0 commit comments

Comments
 (0)