11import { get } from './ajax'
22import { callHook } from '../init/lifecycle'
3- import { getParentPath } from '../router/util'
3+ import { getParentPath , stringifyQuery } from '../router/util'
44import { noop } from '../util/core'
55import { getAndActive } from '../event/sidebar'
66
7- function loadNested ( path , file , next , vm , first ) {
7+ function loadNested ( path , qs , file , next , vm , first ) {
88 path = first ? path : path . replace ( / \/ $ / , '' )
99 path = getParentPath ( path )
1010
1111 if ( ! path ) return
1212
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+ )
1516}
1617
1718export function fetchMixin ( proto ) {
1819 let last
1920 proto . _fetch = function ( cb = noop ) {
20- const { path } = this . route
21+ const { path, query } = this . route
22+ const qs = stringifyQuery ( query , [ 'id' ] )
2123 const { loadNavbar, loadSidebar } = this . config
2224
2325 // Abort last request
2426 last && last . abort && last . abort ( )
2527
26- last = get ( this . router . getFile ( path ) , true )
28+ last = get ( this . router . getFile ( path ) + qs , true )
2729
2830 // Current page is html
2931 this . isHTML = / \. h t m l $ / g. test ( path )
3032
3133 const loadSideAndNav = ( ) => {
3234 if ( ! loadSidebar ) return cb ( )
3335
34- const fn = result => { this . _renderSidebar ( result ) ; cb ( ) }
36+ const fn = result => {
37+ this . _renderSidebar ( result )
38+ cb ( )
39+ }
3540
3641 // Load sidebar
37- loadNested ( path , loadSidebar , fn , this , true )
42+ loadNested ( path , qs , loadSidebar , fn , this , true )
3843 }
3944
4045 // 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+ )
4956
5057 // Load nav
5158 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+ )
5367 }
5468
5569 proto . _fetchCover = function ( ) {
5670 const { coverpage } = this . config
71+ const query = this . route . query
5772 const root = getParentPath ( this . route . path )
5873 const path = this . router . getFile ( root + coverpage )
5974
@@ -63,8 +78,9 @@ export function fetchMixin (proto) {
6378 }
6479
6580 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+ )
6884 }
6985
7086 proto . $fetch = function ( cb = noop ) {
0 commit comments