From 9bb740305b345dbec538f07e476b2d451f7c49f9 Mon Sep 17 00:00:00 2001 From: Guyi Date: Mon, 23 Aug 2021 10:12:17 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-8279=20refactor=EF=BC=9Avue-router?= =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E9=BB=98=E8=AE=A4=E8=B7=B3=E8=BD=AC=20&=20?= =?UTF-8?q?=E6=8A=8Adist=E4=B8=8B=E7=9A=84router.js=E6=9A=B4=E9=9C=B2?= =?UTF-8?q?=E5=87=BA=E6=9D=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .npmignore | 1 + dist/router.js | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/.npmignore b/.npmignore index fec953c4a..d73d4ac34 100644 --- a/.npmignore +++ b/.npmignore @@ -36,6 +36,7 @@ !dist/font/**/* !dist/images/* !dist/images/**/* +!dist/router.js !babel.config.js !babel.config.ie8.js !.eslintrc \ No newline at end of file diff --git a/dist/router.js b/dist/router.js index 04c7b5408..c0e0469a6 100644 --- a/dist/router.js +++ b/dist/router.js @@ -3128,6 +3128,15 @@ this.$router = this._router = BI.Router.$router = $router = new VueRouter({ routes: this.options.routes }); + this.$router.beforeEach(function (to, from, next) { + if (to.matched.length === 0) { + //如果上级也未匹配到路由则跳转主页面,如果上级能匹配到则转上级路由 + from.path ? next({ path: from.path }) : next('/'); + } else { + //如果匹配到正确跳转 + next(); + } + }); this.$router.afterEach(function () { cbs.forEach(function (cb) {cb();}); });