diff --git a/demo/app.js b/demo/app.js index 15b434cdf..fea6d0872 100644 --- a/demo/app.js +++ b/demo/app.js @@ -9,34 +9,47 @@ BI.$(function () { }); var tree = BI.Tree.transformToTreeFormat(Demo.CONFIG); - var obj = { - routes: { - "": "index" - }, - index: function () { - Demo.showIndex = "demo.face"; + var routes = [{ + path: '/', + component: function(){ + return Promise.resolve({ + type: "demo.face" + }) } - }; + }]; BI.Tree.traversal(tree, function (index, node) { if (!node.children || BI.isEmptyArray(node.children)) { - obj.routes[node.text] = node.text; - obj[node.text] = function () { - Demo.showIndex = node.value; - }; + routes.push({ + path: '/' + node.text, + component: function(){ + return Promise.resolve({ + type: node.value + }) + } + }); } }); - var AppRouter = BI.inherit(BI.Router, obj); - new AppRouter; - BI.history.start(); + // var AppRouter = BI.inherit(BI.Router, obj); + // new AppRouter; + // BI.history.start(); BI.createWidget({ - type: "demo.main", + type: "bi.router", ref: function (_ref) { - console.log(_ref); - ref = _ref; + BI.router = _ref._router; }, - element: "#wrapper" + element: "#wrapper", + routes: routes, + render: function () { + return { + type: "demo.main", + ref: function (_ref) { + console.log(_ref); + ref = _ref; + } + } + } }); }); \ No newline at end of file diff --git a/demo/js/center.js b/demo/js/center.js index 11bae6177..e379cdddc 100644 --- a/demo/js/center.js +++ b/demo/js/center.js @@ -5,22 +5,12 @@ Demo.Center = BI.inherit(BI.Widget, { render: function () { var self = this; return { - type: "bi.tab", - ref: function () { - self.tab = this; - }, - single: true, - showIndex: Demo.showIndex, - cardCreator: function (v) { - return BI.createWidget({ - type: v - }); - } - }; + type: "bi.router_view" + } }, setValue: function (v) { - this.tab.setSelect(v); + // this.tab.setSelect(v); } }); BI.shortcut("demo.center", Demo.Center); \ No newline at end of file diff --git a/demo/js/main.store.js b/demo/js/main.store.js index 34f3d3fc6..26ca4b16d 100644 --- a/demo/js/main.store.js +++ b/demo/js/main.store.js @@ -4,12 +4,6 @@ }, - state: function () { - return { - activeCard: Demo.showIndex - }; - }, - computed: {}, watch: {}, @@ -51,12 +45,14 @@ this.model.activeCard = v; var matched = BI.some(Demo.CONFIG, function (index, item) { if (item.value === v) { - BI.history.navigate(item.text, {trigger: true}); + BI.router.push(item.text); + // BI.history.navigate(item.text, {trigger: true}); return true; } }); if (!matched) { - BI.history.navigate("", {trigger: true}); + BI.router.push("/"); + // BI.history.navigate("", {trigger: true}); } } } diff --git a/demo/js/north.js b/demo/js/north.js index 777e25952..90b9b1473 100644 --- a/demo/js/north.js +++ b/demo/js/north.js @@ -13,7 +13,7 @@ Demo.North = BI.inherit(BI.Widget, { listeners: [{ eventName: BI.Button.EVENT_CHANGE, action: function () { - self.fireEvent(Demo.North.EVENT_VALUE_CHANGE, "demo.face"); + self.fireEvent(Demo.North.EVENT_VALUE_CHANGE, ""); } }], cls: "logo", diff --git a/src/router/router2.js b/src/router/router2.js index 626bc30c7..038fa5c23 100644 --- a/src/router/router2.js +++ b/src/router/router2.js @@ -3131,7 +3131,6 @@ }); this._router.afterEach(function () { cbs.forEach(function (cb) {cb();}); - cbs = []; }); this._router.init(this); } @@ -3139,11 +3138,28 @@ BI.shortcut("bi.router", RouterWidget); var RouterView = BI.inherit(BI.Widget, { - beforeInit: function (callback) { - cbs.push(callback); + created: function () { + var self = this; + cbs.push(function () { + self.tab.setSelect($router.history.current.matched[0].path || "/"); + }); }, render: function () { - return $router.history.current.matched[0].components.default; + var self = this; + return { + type: "bi.tab", + ref: function (_ref) { + self.tab = _ref; + }, + single: false, // 是不是单页面 + logic: { + dynamic: false + }, + showIndex: false, + cardCreator: function (v) { + return $router.history.current.matched[0].components.default; + } + }; } }); BI.shortcut("bi.router_view", RouterView);