Skip to content

Commit fa12530

Browse files
ricardogobbosouzapimlie
authored andcommitted
fix: call afterNavigation after nextTick (#478)
* fix: afterNavigation * style: use arrow function
1 parent c6b20eb commit fa12530

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/shared/nav-guards.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ export function addNavGuards (rootVm) {
1919
})
2020

2121
router.afterEach(() => {
22-
const { metaInfo } = resume(rootVm)
22+
rootVm.$nextTick(() => {
23+
const { metaInfo } = resume(rootVm)
2324

24-
if (metaInfo && isFunction(metaInfo.afterNavigation)) {
25-
metaInfo.afterNavigation(metaInfo)
26-
}
25+
if (metaInfo && isFunction(metaInfo.afterNavigation)) {
26+
metaInfo.afterNavigation(metaInfo)
27+
}
28+
})
2729
})
2830
}

test/unit/components.test.js

+4
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@ describe('components', () => {
271271
expect(wrapper.vm.$root._vueMeta.pausing).toBe(true)
272272

273273
guards.after()
274+
expect(afterNavigation).not.toHaveBeenCalled()
275+
await vmTick(wrapper.vm)
274276
expect(afterNavigation).toHaveBeenCalled()
275277
})
276278

@@ -306,6 +308,8 @@ describe('components', () => {
306308
expect(wrapper.vm.$root._vueMeta.pausing).toBe(true)
307309

308310
guards.after()
311+
expect(afterNavigation).not.toHaveBeenCalled()
312+
await vmTick(wrapper.vm)
309313
expect(afterNavigation).toHaveBeenCalled()
310314
})
311315

0 commit comments

Comments
 (0)