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

时间:2018-04-21 07:23:50

标签: javascript angularjs reactjs angularjs-directive

我的AngularJS和ReactJS都在同一页面上运行。

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

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

2 个答案:

答案 0 :(得分:0)

根据您的问题,您可以做的是,不要在href标记中添加<a>属性。而是将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);
 }

答案 1 :(得分:0)

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

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

因此它不会处理任何点击方案。