【问题标题】:How to find the bit of code that causes involuntary routing? (in a legacy website)如何找到导致非自愿路由的代码位? (在旧网站中)
【发布时间】:2018-11-15 09:47:17
【问题描述】:

请帮助我,我正在重用一个基于 AngularJS 的旧网站,但我不断遇到由未知代码引起的意外路由事件。

当我按下网站上的各种元素时,它们都没有明显的事件处理程序 使用这样的代码,路由会按预期导致“页面未找到”页面。

我已经在“$location”和“$route”的所有引用周围放置了断点。我已经查找了代码中的所有“href”属性 我没有发现任何可疑之处。

当我在 '$routeChangeStart' 钩子中设置断点时,如下所示

    $rootScope.$on('$routeChangeStart', function (event, next, current) {

    debugger;
    //.....
}

我有以下物品:

    next = { 
            params: {}
            pathParams: {} 
           } 

(没有“$$route”)

event = {
   currentScope: m {$id: 2, $$childTail: m, $$childHead: m, $$prevSibling: null, 
   $$nextSibling: null, …}
   defaultPrevented: false
   name: "$routeChangeStart"
   preventDefault: ƒ ()
   targetScope: m {$id: 2, $$childTail: m, $$childHead: m, $$prevSibling: null, 
   $$nextSibling: null, …}
}

(targetScope==currentScope) 为真

该项目还使用了 Kendo 和 JQuery

我确实意识到我不能期待任何具体的答案,但欢迎任何建议。

我应该去哪里看?

【问题讨论】:

    标签: javascript angularjs routing legacy-code


    【解决方案1】:

    我必须做的是检查调试器中的调用堆栈在断点处停止

    $rootScope.$on('$routeChangeStart' ...
    

    pathParams 为空,因为路由无效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-12
      • 2014-04-17
      • 2016-03-28
      • 2019-06-07
      • 2014-04-30
      • 1970-01-01
      相关资源
      最近更新 更多