From 29e259f175dcf8a5daf349803996593ccb4f00da Mon Sep 17 00:00:00 2001 From: Guyi Date: Wed, 25 Aug 2021 21:42:47 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-8279=20refactor=EF=BC=9Arouter-view?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=8C=B9=E9=85=8D=E5=88=B0=E7=9A=84=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E5=8E=BB=E6=93=8D=E4=BD=9Ctab?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/app.js | 45 ++++++++++++++++++++++++++++++++++++++++++++- dist/router.js | 13 +++++++++++-- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/demo/app.js b/demo/app.js index c4cdf8dad..acbc2cd77 100644 --- a/demo/app.js +++ b/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) { diff --git a/dist/router.js b/dist/router.js index c1addf567..6e2c2a337 100644 --- a/dist/router.js +++ b/dist/router.js @@ -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,7 +3177,7 @@ }, showIndex: false, cardCreator: function (v) { - return $router.history.current.matched[o.deps].components.default; + return $router.history.current.matched[o.deps].components.default; } }; },