fix: ignore non-html links in router and prefetch

pull/207/head
Evan You 4 years ago
parent 122e0263bd
commit 3e6e61bcea

@ -75,6 +75,11 @@ export function usePrefetch() {
rIC(() => { rIC(() => {
document.querySelectorAll('#app a').forEach((link) => { document.querySelectorAll('#app a').forEach((link) => {
const { target, hostname, pathname } = link as HTMLAnchorElement const { target, hostname, pathname } = link as HTMLAnchorElement
const extMatch = pathname.match(/\.\w+$/)
if (extMatch && extMatch[0] !== '.html') {
return
}
if ( if (
// only prefetch same tab navigation, since a new tab will load // only prefetch same tab navigation, since a new tab will load
// the lean js chunk instead. // the lean js chunk instead.

@ -114,6 +114,7 @@ export function createRouter(
if (link) { if (link) {
const { href, protocol, hostname, pathname, hash, target } = link const { href, protocol, hostname, pathname, hash, target } = link
const currentUrl = window.location const currentUrl = window.location
const extMatch = pathname.match(/\.\w+$/)
// only intercept inbound links // only intercept inbound links
if ( if (
!e.ctrlKey && !e.ctrlKey &&
@ -122,7 +123,8 @@ export function createRouter(
!e.metaKey && !e.metaKey &&
target !== `_blank` && target !== `_blank` &&
protocol === currentUrl.protocol && protocol === currentUrl.protocol &&
hostname === currentUrl.hostname hostname === currentUrl.hostname &&
!(extMatch && extMatch[0] !== '.html')
) { ) {
e.preventDefault() e.preventDefault()
if (pathname === currentUrl.pathname) { if (pathname === currentUrl.pathname) {

Loading…
Cancel
Save