11import { get } from './ajax'
22import { callHook } from '../init/lifecycle'
3- import { getRoot } from '../route/util'
3+ import { getParentPath } from '../route/util'
44import { noop } from '../util/core'
55
6+ function loadNested ( path , file , next , vm , first ) {
7+ path = first ? path : path . replace ( / \/ $ / , '' )
8+ path = getParentPath ( path )
9+
10+ if ( ! path ) return
11+
12+ get ( vm . $getFile ( path + file ) )
13+ . then ( next , _ => loadNested ( path , file , next , vm ) )
14+ }
15+
616export function fetchMixin ( proto ) {
717 let last
818 proto . _fetch = function ( cb = noop ) {
919 const { path } = this . route
1020 const { loadNavbar, loadSidebar } = this . config
11- const root = getRoot ( path )
1221
1322 // Abort last request
1423 last && last . abort && last . abort ( )
@@ -26,25 +35,18 @@ export function fetchMixin (proto) {
2635 const fn = result => { this . _renderSidebar ( result ) ; cb ( ) }
2736
2837 // Load sidebar
29- get ( this . $getFile ( root + loadSidebar ) )
30- // fallback root navbar when fail
31- . then ( fn , _ => get ( loadSidebar ) . then ( fn ) )
38+ loadNested ( path , loadSidebar , fn , this , true )
3239 } ,
3340 _ => this . _renderMain ( null ) )
3441
3542 // Load nav
3643 loadNavbar &&
37- get ( this . $getFile ( root + loadNavbar ) )
38- . then (
39- text => this . _renderNav ( text ) ,
40- // fallback root navbar when fail
41- _ => get ( loadNavbar ) . then ( text => this . _renderNav ( text ) )
42- )
44+ loadNested ( path , loadNavbar , text => this . _renderNav ( text ) , this , true )
4345 }
4446
4547 proto . _fetchCover = function ( ) {
4648 const { coverpage } = this . config
47- const root = getRoot ( this . route . path )
49+ const root = getParentPath ( this . route . path )
4850 const path = this . $getFile ( root + coverpage )
4951
5052 if ( this . route . path !== '/' || ! coverpage ) {
0 commit comments