[FIX] router: do not prevent default click on <a> in some cases

This commit is contained in:
Géry Debongnie
2019-08-06 07:35:02 +02:00
parent 6cd5ec10f0
commit 635a7fc72c
3 changed files with 49 additions and 4 deletions
+18 -2
View File
@@ -5,7 +5,7 @@ export const LINK_TEMPLATE_NAME = "__owl__-router-link";
export const LINK_TEMPLATE = `
<a t-att-class="{'router-link-active': isActive }"
t-att-href="href"
t-on-click.prevent="navigate">
t-on-click="navigate">
<t t-slot="default"/>
</a>`;
@@ -26,7 +26,23 @@ export class Link<Env extends RouterEnv> extends Component<Env, Props, {}> {
return (<any>document.location).pathname === this.href;
}
navigate() {
navigate(ev) {
// don't redirect with control keys
if (ev.metaKey || ev.altKey || ev.ctrlKey || ev.shiftKey) {
return;
}
// don't redirect on right click
if (ev.button !== undefined && ev.button !== 0) {
return;
}
// don't redirect if `target="_blank"`
if (ev.currentTarget && ev.currentTarget.getAttribute) {
const target = ev.currentTarget.getAttribute("target");
if (/\b_blank\b/i.test(target)) {
return;
}
}
ev.preventDefault();
this.env.router.navigate(this.props);
}
}