1
1
import { get } from './ajax'
2
2
import { callHook } from '../init/lifecycle'
3
- import { getParentPath } from '../router/util'
3
+ import { getParentPath , stringifyQuery } from '../router/util'
4
4
import { noop } from '../util/core'
5
5
import { getAndActive } from '../event/sidebar'
6
6
7
- function loadNested ( path , file , next , vm , first ) {
7
+ function loadNested ( path , qs , file , next , vm , first ) {
8
8
path = first ? path : path . replace ( / \/ $ / , '' )
9
9
path = getParentPath ( path )
10
10
11
11
if ( ! path ) return
12
12
13
- get ( vm . router . getFile ( path + file ) )
14
- . then ( next , _ => loadNested ( path , file , next , vm ) )
13
+ get ( vm . router . getFile ( path + file ) + qs ) . then ( next , _ =>
14
+ loadNested ( path , qs , file , next , vm )
15
+ )
15
16
}
16
17
17
18
export function fetchMixin ( proto ) {
18
19
let last
19
20
proto . _fetch = function ( cb = noop ) {
20
- const { path } = this . route
21
+ const { path, query } = this . route
22
+ const qs = stringifyQuery ( query , [ 'id' ] )
21
23
const { loadNavbar, loadSidebar } = this . config
22
24
23
25
// Abort last request
24
26
last && last . abort && last . abort ( )
25
27
26
- last = get ( this . router . getFile ( path ) , true )
28
+ last = get ( this . router . getFile ( path ) + qs , true )
27
29
28
30
// Current page is html
29
31
this . isHTML = / \. h t m l $ / g. test ( path )
30
32
31
33
const loadSideAndNav = ( ) => {
32
34
if ( ! loadSidebar ) return cb ( )
33
35
34
- const fn = result => { this . _renderSidebar ( result ) ; cb ( ) }
36
+ const fn = result => {
37
+ this . _renderSidebar ( result )
38
+ cb ( )
39
+ }
35
40
36
41
// Load sidebar
37
- loadNested ( path , loadSidebar , fn , this , true )
42
+ loadNested ( path , qs , loadSidebar , fn , this , true )
38
43
}
39
44
40
45
// Load main content
41
- last . then ( ( text , opt ) => {
42
- this . _renderMain ( text , opt )
43
- loadSideAndNav ( )
44
- } ,
45
- _ => {
46
- this . _renderMain ( null )
47
- loadSideAndNav ( )
48
- } )
46
+ last . then (
47
+ ( text , opt ) => {
48
+ this . _renderMain ( text , opt )
49
+ loadSideAndNav ( )
50
+ } ,
51
+ _ => {
52
+ this . _renderMain ( null )
53
+ loadSideAndNav ( )
54
+ }
55
+ )
49
56
50
57
// Load nav
51
58
loadNavbar &&
52
- loadNested ( path , loadNavbar , text => this . _renderNav ( text ) , this , true )
59
+ loadNested (
60
+ path ,
61
+ qs ,
62
+ loadNavbar ,
63
+ text => this . _renderNav ( text ) ,
64
+ this ,
65
+ true
66
+ )
53
67
}
54
68
55
69
proto . _fetchCover = function ( ) {
56
70
const { coverpage } = this . config
71
+ const query = this . route . query
57
72
const root = getParentPath ( this . route . path )
58
73
const path = this . router . getFile ( root + coverpage )
59
74
@@ -63,8 +78,9 @@ export function fetchMixin (proto) {
63
78
}
64
79
65
80
this . coverIsHTML = / \. h t m l $ / g. test ( path )
66
- get ( path )
67
- . then ( text => this . _renderCover ( text ) )
81
+ get ( path + stringifyQuery ( query , [ 'id' ] ) ) . then ( text =>
82
+ this . _renderCover ( text )
83
+ )
68
84
}
69
85
70
86
proto . $fetch = function ( cb = noop ) {
0 commit comments