From 7f55411cf86aec70cf5ed496271f0ea4353a0131 Mon Sep 17 00:00:00 2001 From: zrh122 <1229550935@qq.com> Date: Sat, 30 Mar 2019 13:57:38 +0800 Subject: [PATCH 1/2] fix(router-view): register instance in init hook close #2561 --- src/components/view.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/components/view.js b/src/components/view.js index f6183a0f4..25bdd0057 100644 --- a/src/components/view.js +++ b/src/components/view.js @@ -69,6 +69,17 @@ export default { matched.instances[name] = vnode.componentInstance } + // register instance in init hook + // in case kept-alive component be actived when routes changed + data.hook.init = (vnode) => { + if (vnode.data.keepAlive && + vnode.componentInstance && + vnode.componentInstance !== matched.instances[name] + ) { + matched.instances[name] = vnode.componentInstance + } + } + // resolve props let propsToPass = data.props = resolveProps(route, matched.props && matched.props[name]) if (propsToPass) { From 4a3a51a8d8d6688c1316249fa9ccdaf37cbfe7f9 Mon Sep 17 00:00:00 2001 From: zrh122 <1229550935@qq.com> Date: Sun, 31 Mar 2019 05:26:05 +0800 Subject: [PATCH 2/2] test: add e2e test for #2561 --- examples/index.html | 1 + examples/navigation-guard-callback/app.js | 74 +++++++++++++++++++ examples/navigation-guard-callback/index.html | 10 +++ test/e2e/specs/navigation-guard-callback.js | 48 ++++++++++++ 4 files changed, 133 insertions(+) create mode 100644 examples/navigation-guard-callback/app.js create mode 100644 examples/navigation-guard-callback/index.html create mode 100644 test/e2e/specs/navigation-guard-callback.js diff --git a/examples/index.html b/examples/index.html index f2bdf7225..2e2233bd6 100644 --- a/examples/index.html +++ b/examples/index.html @@ -25,6 +25,7 @@