繁体   English   中英

如何在ReactJS锚标记上停止Angular $ rootElement.on('click')?

[英]How to stop Angular $rootElement.on('click') on ReactJS anchor tag?

我已经在同一页面上运行了AngularJS和ReactJS。

但是,当我单击任何ReactJS <a>标记时,Angular的$rootElement.on('click)被触发并进行页面重定向。 我想在页面重定向之前在ReactJS中做一些功能。

我不想在ReactJS中进行更改,有人可以建议我如何在Angular中处理这种情况吗?

从您的问题出发,您可以做的是不要在<a>标记中添加href属性。 而是将routing位置传递给函数:

<a ng-click="redirect(your_routing_path)">Somethink</a>

并在控制器中:

$scope.redirect = function(your_routing_path){
     // do what React gotta do and then redirect
     $location.path(your_routing_path);
 }

我找到了解决方案。 在角度run我们可以简单地编写以下代码块:

/**
 * We do not need to handle on-click handler if element belongs to reactJS.
 */
 $rootElement.off('click', '[data-reactid]');

因此,它不会处理任何单击情况。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM