如何在 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);
 }

我找到了解决办法。在 angular run 中,我们可以简单地编写以下代码块:

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

所以它不会处理任何点击场景。