From ccf4c7c5cc21dccbf1aa0db08304056612225f17 Mon Sep 17 00:00:00 2001 From: "qingwei.li" Date: Fri, 2 Jun 2017 22:12:07 +0800 Subject: [PATCH] fix(compiler): force reset toc when rendering sidebar fixed #181 --- src/core/render/compiler.js | 4 ++++ src/core/render/index.js | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/core/render/compiler.js b/src/core/render/compiler.js index e12176657..aafaa90bd 100644 --- a/src/core/render/compiler.js +++ b/src/core/render/compiler.js @@ -135,6 +135,10 @@ export class Compiler { * Compile sub sidebar */ subSidebar (level) { + if (!level) { + this.toc = [] + return + } const currentPath = this.router.getCurrentPath() const { cacheTree, toc } = this diff --git a/src/core/render/index.js b/src/core/render/index.js index b672bb6ff..92e3c6b56 100644 --- a/src/core/render/index.js +++ b/src/core/render/index.js @@ -85,6 +85,9 @@ export function renderMixin (proto) { const activeEl = getAndActive(this.router, '.sidebar-nav', true, true) if (loadSidebar && activeEl) { activeEl.parentNode.innerHTML += this.compiler.subSidebar(subMaxLevel) + } else { + // reset toc + this.compiler.subSidebar() } // bind event this._bindEventOnRendered()