防止路由器导航到href

时间:2018-01-06 12:32:53

标签: aurelia aurelia-router

我有一个指向我的某条路线的route-href属性的链接。一切正常:

<a route-href="route: item; params.bind: {id: item.id}">${item.name}</a>

我现在创建了自己的自定义属性route-popup,使用<compose>以固定的叠加层打开路线,这也很好用:

<a route-popup="route: item; params.bind: {id: item.id}">${item.name}</a>

但是,为了让用户能够在新窗口中按住Ctrl并单击并打开项目,我想在链接上同时使用route-href route-popup

<a route-href="route: item; params.bind: {id: item.id}" route-popup="route: item; params.bind: {id: item.id}">${item.name}</a>

然后从我的RoutePopupCustomAttribute班级preventDefault()开始,以便route-href(或它创建的href)被抑制:

this.onClick = e => {
    e.preventDefault();
    e.stopPropagation();

    this.ea.publish('route-popup:open', {route: this.route, params: this.params});

    return false;
};

但是,我的回调中的preventDefaultstopPropagation或返回false似乎都无效。 Aurelia仍然遵循href并呈现新页面。

如何阻止路由器导航到route-href

编辑:好的,所以这有点奇怪,我设置了一个gist.run来进一步解释这个问题,然而,在gist.run上它确实有效:/所有需要的是{{1} }。我的代码唯一的区别是我在路由器配置中使用e.preventDefault(),所以我猜测它是什么?

https://gist.run/?id=daf226363df8cdc777be718bff3a4f76

是的,经过进一步测试后发现,当您使用pushState: true时,pushState: true无法使用preventDefault(),而如果您使用hashChange: true则为{。}}。

0 个答案:

没有答案
相关问题