Skip to content

Commit c4abc95

Browse files
authored
fix: wrong recognition of non-html extension leads to route error (#3218)
1 parent 672e494 commit c4abc95

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

Diff for: package.json

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"focus-trap": "^7.5.4",
101101
"mark.js": "8.11.1",
102102
"minisearch": "^6.2.0",
103+
"mrmime": "^1.0.1",
103104
"shiki": "^0.14.5",
104105
"vite": "^5.0.0",
105106
"vue": "^3.3.8"

Diff for: pnpm-lock.yaml

+7-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: src/client/app/router.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { reactive, inject, markRaw, nextTick, readonly } from 'vue'
22
import type { Component, InjectionKey } from 'vue'
3+
import { lookup } from 'mrmime'
34
import { notFoundPageData } from '../shared'
45
import type { PageData, PageDataPayload, Awaitable } from '../shared'
56
import { inBrowser, withBase } from './utils'
@@ -181,7 +182,6 @@ export function createRouter(
181182
link.baseURI
182183
)
183184
const currentUrl = window.location
184-
const extMatch = pathname.match(/\.\w+$/)
185185
// only intercept inbound links
186186
if (
187187
!e.ctrlKey &&
@@ -191,7 +191,9 @@ export function createRouter(
191191
!target &&
192192
origin === currentUrl.origin &&
193193
// don't intercept if non-html extension is present
194-
!(extMatch && extMatch[0] !== '.html')
194+
!(siteDataRef.value.cleanUrls
195+
? lookup(pathname)
196+
: lookup(pathname) !== 'text/html')
195197
) {
196198
e.preventDefault()
197199
if (

Diff for: src/client/theme-default/support/utils.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { withBase } from 'vitepress'
2+
import { lookup } from 'mrmime'
23
import { useData } from '../composables/data'
34
import { isExternal } from '../../shared'
45

@@ -27,7 +28,7 @@ export function normalizeLink(url: string): string {
2728
isExternal(url) ||
2829
url.startsWith('#') ||
2930
!protocol.startsWith('http') ||
30-
/\.(?!html|md)\w+($|\?)/i.test(url)
31+
(/\.(?!html|md)\w+($|\?)/i.test(url) && lookup(url))
3132
)
3233
return url
3334

0 commit comments

Comments
 (0)