@@ -23,7 +23,7 @@ if (module.hot) {
23
23
if ( siteData . base !== prevBase ) {
24
24
window . alert (
25
25
`[vuepress] Site base has changed. ` +
26
- `Please restart dev server to ensure correct asset paths.`
26
+ `Please restart dev server to ensure correct asset paths.`
27
27
)
28
28
}
29
29
} )
@@ -62,15 +62,25 @@ export function createApp (isServer) {
62
62
base : siteData . base ,
63
63
mode : 'history' ,
64
64
fallback : false ,
65
- routes
65
+ routes,
66
+ scrollBehavior ( to , from , savedPosition ) {
67
+ if ( savedPosition ) {
68
+ return savedPosition
69
+ }
70
+ if ( to . path !== from . path ) {
71
+ return { x : 0 , y : 0 }
72
+ }
73
+ }
66
74
} )
67
75
68
76
// redirect /foo to /foo/
69
77
router . beforeEach ( ( to , from , next ) => {
70
78
if ( ! / ( \/ | \. h t m l ) $ / . test ( to . path ) ) {
71
- next ( Object . assign ( { } , to , {
72
- path : to . path + '/'
73
- } ) )
79
+ next (
80
+ Object . assign ( { } , to , {
81
+ path : to . path + '/'
82
+ } )
83
+ )
74
84
} else {
75
85
next ( )
76
86
}
@@ -94,7 +104,11 @@ export function createApp (isServer) {
94
104
render ( h ) {
95
105
return h ( 'div' , { attrs : { id : 'app' } } , [
96
106
h ( 'router-view' , { ref : 'layout' } ) ,
97
- h ( 'div' , { class : 'global-ui' } , globalUIComponents . map ( component => h ( component ) ) )
107
+ h (
108
+ 'div' ,
109
+ { class : 'global-ui' } ,
110
+ globalUIComponents . map ( component => h ( component ) )
111
+ )
98
112
] )
99
113
}
100
114
} )
0 commit comments