Skip to content

Commit

Permalink
fix: ignore non-html links in router and prefetch
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jan 13, 2021
1 parent 122e026 commit 3e6e61b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/client/app/composables/preFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ export function usePrefetch() {
rIC(() => {
document.querySelectorAll('#app a').forEach((link) => {
const { target, hostname, pathname } = link as HTMLAnchorElement
const extMatch = pathname.match(/\.\w+$/)
if (extMatch && extMatch[0] !== '.html') {
return
}

if (
// only prefetch same tab navigation, since a new tab will load
// the lean js chunk instead.
Expand Down
4 changes: 3 additions & 1 deletion src/client/app/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export function createRouter(
if (link) {
const { href, protocol, hostname, pathname, hash, target } = link
const currentUrl = window.location
const extMatch = pathname.match(/\.\w+$/)
// only intercept inbound links
if (
!e.ctrlKey &&
Expand All @@ -122,7 +123,8 @@ export function createRouter(
!e.metaKey &&
target !== `_blank` &&
protocol === currentUrl.protocol &&
hostname === currentUrl.hostname
hostname === currentUrl.hostname &&
!(extMatch && extMatch[0] !== '.html')
) {
e.preventDefault()
if (pathname === currentUrl.pathname) {
Expand Down

0 comments on commit 3e6e61b

Please sign in to comment.