Browse Source

Pull request #2128: KERNEL-8279 refactor:router-view根据匹配到的路径去操作tab

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

* commit 'b420ecf14bf6a3b23635fa9646b5f0f0c902cb93':
  KERNEL-8279 refactor:router-view销毁时移除callbacklistener
  KERNEL-8279 refactor:router-view根据匹配到的路径去操作tab
es6
Guyi 3 years ago
parent
commit
3f538f37ca
  1. 45
      demo/app.js
  2. 15
      dist/router.js

45
demo/app.js

@ -23,7 +23,50 @@ BI.$(function () {
return Promise.resolve({
type: "demo.router"
});
}
},
}, {
name: "user",
path: "/user/:name",
component: function () {
return Promise.resolve({
type: "bi.vtape",
items: [{
type: "bi.label",
text: "user",
height: 50
}, {
type: "bi.router_view",
deps: 1
}]
});
},
children: [{
path: '',
component: function () {
return Promise.resolve({
type: "bi.label",
text: 'home'
})
}
}, {
name: 'dashboard',
path: 'dashboard',
component: function () {
return Promise.resolve({
type: "bi.label",
text: 'dashboard'
})
}
}, {
name: 'tables',
path: 'tables/:id',
component: function () {
return Promise.resolve({
type: "bi.label",
text: 'tables'
})
}
}]
}];
// BI.Tree.traversal(tree, function (index, node) {

15
dist/router.js vendored

@ -3152,7 +3152,16 @@
created: function () {
var self = this, o = this.options;
cbs.push(this._callbackListener = function () {
self.tab.setSelect($router.history.current.fullPath || "/");
var current = $router.history.current;
// 匹配的路径名(/component/:id)
var matchedPath = current.matched[o.deps] && current.matched[o.deps].path;
if (matchedPath) {
BI.each(current.params, function (key, value) {
// 把 :id 替换成具体的值(/component/demo.td)
matchedPath = matchedPath.replace(`:${key}`, value);
});
}
self.tab.setSelect(matchedPath || "/");
});
},
render: function () {
@ -3168,12 +3177,12 @@
},
showIndex: false,
cardCreator: function (v) {
return $router.history.current.matched[o.deps].components.default;
return $router.history.current.matched[o.deps].components.default;
}
};
},
destroyed: function () {
BI.remove(cbs, this._callbackListener);
cbs.remove(this._callbackListener);
}
});
BI.shortcut("bi.router_view", BI.RouterView);

Loading…
Cancel
Save