From 750c877be37e698cfb12638be7da8ea05bf4c54f Mon Sep 17 00:00:00 2001 From: Guyi Date: Wed, 1 Jun 2022 14:07:08 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E6=97=A0JIRA=E4=BB=BB=E5=8A=A1=20?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E9=97=AE=E9=A2=98"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit b36b1a4690ead1975157263f5d6efc6ab8e75662. --- src/router/router.js | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/src/router/router.js b/src/router/router.js index 3a90bfbce..4d296f124 100644 --- a/src/router/router.js +++ b/src/router/router.js @@ -3156,27 +3156,24 @@ }, created: function () { var self = this, o = this.options; - // 嵌套路由 + single 下父亲执行setSelect后会执行一遍push + _callbackListener,之后在cbs.forEach下会执行到刚push进去的_callbackListener导致执行两次,这里加一个nextTick让forEach走不到新push进去的方法。 - BI.nextTick(function () { - cbs.push(self._callbackListener = function () { - var current = $router.history.current; - // 匹配的路径名(/component/:id) - var matchedPath = current.matched[o.deps] && current.matched[o.deps].path; - var component = current.matched[o.deps] && current.matched[o.deps].components[o.name]; - - if (BI.isNotNull(component)) { - if (matchedPath) { - BI.each(current.params, function (key, value) { - // 把 :id 替换成具体的值(/component/demo.td) - matchedPath = matchedPath.replace(`:${key}`, value); - }); - } - self.tab.setSelect(matchedPath || "/"); + cbs.push(this._callbackListener = function () { + var current = $router.history.current; + // 匹配的路径名(/component/:id) + var matchedPath = current.matched[o.deps] && current.matched[o.deps].path; + var component = current.matched[o.deps] && current.matched[o.deps].components[o.name]; + + if (BI.isNotNull(component)) { + if (matchedPath) { + BI.each(current.params, function (key, value) { + // 把 :id 替换成具体的值(/component/demo.td) + matchedPath = matchedPath.replace(`:${key}`, value); + }); } - }); - // "bi.router_view"是由"bi.tab"实现的,cardCreator是一个异步过程,在"bi.router_view"创建之前,cbs里不会有创建子组件的方法,在初始化路由时,没法直接渲染到子组件,所以这里手动加了一次调用 - self._callbackListener(); + self.tab.setSelect(matchedPath || "/"); + } }); + // "bi.router_view"是由"bi.tab"实现的,cardCreator是一个异步过程,在"bi.router_view"创建之前,cbs里不会有创建子组件的方法,在初始化路由时,没法直接渲染到子组件,所以这里手动加了一次调用 + this._callbackListener(); }, render: function () { var self = this, o = this.options; @@ -3197,8 +3194,7 @@ }; }, destroyed: function () { - // BI.remove方法会把第二个参数当迭代器执行导致方法多执行一遍 - cbs.splice(cbs.indexOf(this._callbackListener), 1); + BI.remove(cbs, this._callbackListener); } }); BI.shortcut("bi.router_view", BI.RouterView);