Skip to content

Commit 3e6e61b

Browse files
committed
fix: ignore non-html links in router and prefetch
1 parent 122e026 commit 3e6e61b

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/client/app/composables/preFetch.ts

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ export function usePrefetch() {
7575
rIC(() => {
7676
document.querySelectorAll('#app a').forEach((link) => {
7777
const { target, hostname, pathname } = link as HTMLAnchorElement
78+
const extMatch = pathname.match(/\.\w+$/)
79+
if (extMatch && extMatch[0] !== '.html') {
80+
return
81+
}
82+
7883
if (
7984
// only prefetch same tab navigation, since a new tab will load
8085
// the lean js chunk instead.

src/client/app/router.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export function createRouter(
114114
if (link) {
115115
const { href, protocol, hostname, pathname, hash, target } = link
116116
const currentUrl = window.location
117+
const extMatch = pathname.match(/\.\w+$/)
117118
// only intercept inbound links
118119
if (
119120
!e.ctrlKey &&
@@ -122,7 +123,8 @@ export function createRouter(
122123
!e.metaKey &&
123124
target !== `_blank` &&
124125
protocol === currentUrl.protocol &&
125-
hostname === currentUrl.hostname
126+
hostname === currentUrl.hostname &&
127+
!(extMatch && extMatch[0] !== '.html')
126128
) {
127129
e.preventDefault()
128130
if (pathname === currentUrl.pathname) {

0 commit comments

Comments
 (0)