diff --git a/src/store.js b/src/store.js index efc22bf8..631375a0 100644 --- a/src/store.js +++ b/src/store.js @@ -211,8 +211,20 @@ const store = new Vuex.Store({ : [] }, - sidebar(_, {config}) { + sidebar(state, {config}) { const sidebar = config.sidebar || [] + if (sidebar === 'auto') { + return [ + { + children: [ + { + title: state.page && state.page.title, + link: state.route && state.route.path + } + ] + } + ] + } return typeof sidebar === 'function' ? sidebar(store) : sidebar }, diff --git a/website/docs/options.md b/website/docs/options.md index 7cb5a4b6..012898e6 100644 --- a/website/docs/options.md +++ b/website/docs/options.md @@ -61,6 +61,14 @@ interface SidebarItemLink { } ``` +- If you want to automatically generate a sidebar from nav header, set sidebar to auto mode + +```javascript +{ + sidebar: 'auto' +} +``` + ## sourcePath - Type: `string` diff --git a/website/docs/zh/options.md b/website/docs/zh/options.md index 36329e30..dcd2657e 100644 --- a/website/docs/zh/options.md +++ b/website/docs/zh/options.md @@ -61,6 +61,14 @@ interface ItemLink { } ``` +- 如果要从导航标题自动生成侧边栏,请将侧边栏设置为自动模式 + +```javascript +{ + sidebar: 'auto' +} +``` + ## sourcePath - 类型:`string`