Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Tinro should rewrite links on auxclick event too #111

Open
mildred opened this issue May 25, 2022 · 0 comments
Open

Tinro should rewrite links on auxclick event too #111

mildred opened this issue May 25, 2022 · 0 comments

Comments

@mildred
Copy link

mildred commented May 25, 2022

When clicking a link, tinro aitomatically prepend the link with #/ to ensure we stay on the same page. This works well except when middle-clicking. In that case, Tinro should listen to the auxclick event to perform the same task.

https://developer.mozilla.org/en-US/docs/Web/API/Element/auxclick_event

The current implementation:

tinro/src/router.js

Lines 62 to 81 in 32038e7

function aClickListener(go){
const h = e => {
const a = e.target.closest('a[href]');
const target = a && getAttr(a,'target',false,'_self');
const ignore = a && getAttr(a,'tinro-ignore');
const key = e.ctrlKey || e.metaKey || e.altKey || e.shiftKey;
if(target == '_self' && !ignore && !key && a){
const href = a.getAttribute('href').replace(/^\/#/,'');
if(!/^\/\/|^#|^[a-zA-Z]+:/.test(href)) {
e.preventDefault();
go(href.startsWith('/') ? href : a.href.replace(window.location.origin,''));
}
}
}
addEventListener('click', h);
return () => removeEventListener('click', h);
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant