1
1
import { get } from './ajax'
2
2
import { callHook } from '../init/lifecycle'
3
- import { getRoot } from '../route/util'
3
+ import { getParentPath } from '../route/util'
4
4
import { noop } from '../util/core'
5
5
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
+
6
16
export function fetchMixin ( proto ) {
7
17
let last
8
18
proto . _fetch = function ( cb = noop ) {
9
19
const { path } = this . route
10
20
const { loadNavbar, loadSidebar } = this . config
11
- const root = getRoot ( path )
12
21
13
22
// Abort last request
14
23
last && last . abort && last . abort ( )
@@ -26,25 +35,18 @@ export function fetchMixin (proto) {
26
35
const fn = result => { this . _renderSidebar ( result ) ; cb ( ) }
27
36
28
37
// 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 )
32
39
} ,
33
40
_ => this . _renderMain ( null ) )
34
41
35
42
// Load nav
36
43
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 )
43
45
}
44
46
45
47
proto . _fetchCover = function ( ) {
46
48
const { coverpage } = this . config
47
- const root = getRoot ( this . route . path )
49
+ const root = getParentPath ( this . route . path )
48
50
const path = this . $getFile ( root + coverpage )
49
51
50
52
if ( this . route . path !== '/' || ! coverpage ) {
0 commit comments