Browse Source

Pull request #2701: 无JIRA任务 路由问题

Merge in VISUAL/fineui from ~KOBI/fineui:master to master

* commit 'b36b1a4690ead1975157263f5d6efc6ab8e75662':
  无JIRA任务 路由问题
  无JIRA任务 格式
  无JIRA任务 router支持base和mode
  无JIRA任务 router支持base和mode
es6
Kobi 3 years ago
parent
commit
576e5a61b5
  1. 38
      src/router/router.js

38
src/router/router.js

@ -3155,24 +3155,27 @@
}, },
created: function () { created: function () {
var self = this, o = this.options; var self = this, o = this.options;
cbs.push(this._callbackListener = function () { // 嵌套路由 + single 下父亲执行setSelect后会执行一遍push + _callbackListener,之后在cbs.forEach下会执行到刚push进去的_callbackListener导致执行两次,这里加一个nextTick让forEach走不到新push进去的方法。
var current = $router.history.current; BI.nextTick(function () {
// 匹配的路径名(/component/:id) cbs.push(self._callbackListener = function () {
var matchedPath = current.matched[o.deps] && current.matched[o.deps].path; var current = $router.history.current;
var component = current.matched[o.deps] && current.matched[o.deps].components[o.name]; // 匹配的路径名(/component/:id)
var matchedPath = current.matched[o.deps] && current.matched[o.deps].path;
if (BI.isNotNull(component)) { var component = current.matched[o.deps] && current.matched[o.deps].components[o.name];
if (matchedPath) {
BI.each(current.params, function (key, value) { if (BI.isNotNull(component)) {
// 把 :id 替换成具体的值(/component/demo.td) if (matchedPath) {
matchedPath = matchedPath.replace(`:${key}`, value); BI.each(current.params, function (key, value) {
}); // 把 :id 替换成具体的值(/component/demo.td)
matchedPath = matchedPath.replace(`:${key}`, value);
});
}
self.tab.setSelect(matchedPath || "/");
} }
self.tab.setSelect(matchedPath || "/"); });
} // "bi.router_view"是由"bi.tab"实现的,cardCreator是一个异步过程,在"bi.router_view"创建之前,cbs里不会有创建子组件的方法,在初始化路由时,没法直接渲染到子组件,所以这里手动加了一次调用
self._callbackListener();
}); });
// "bi.router_view"是由"bi.tab"实现的,cardCreator是一个异步过程,在"bi.router_view"创建之前,cbs里不会有创建子组件的方法,在初始化路由时,没法直接渲染到子组件,所以这里手动加了一次调用
this._callbackListener();
}, },
render: function () { render: function () {
var self = this, o = this.options; var self = this, o = this.options;
@ -3193,7 +3196,8 @@
}; };
}, },
destroyed: function () { destroyed: function () {
BI.remove(cbs, this._callbackListener); // BI.remove方法会把第二个参数当迭代器执行导致方法多执行一遍
cbs.splice(cbs.indexOf(this._callbackListener), 1);
} }
}); });
BI.shortcut("bi.router_view", BI.RouterView); BI.shortcut("bi.router_view", BI.RouterView);

Loading…
Cancel
Save