@@ -6,23 +6,38 @@ import {
6
6
inject ,
7
7
watchEffect ,
8
8
shallowRef
9
- } from 'vue'
9
+ } from '/@modules/ vue'
10
10
import { Layout } from '/@theme/index.js'
11
11
12
12
const PathSymbol = Symbol ( )
13
13
14
14
const App = {
15
15
setup ( ) {
16
- const path = ref ( window . location . pathname )
16
+ const path = ref ( location . pathname )
17
17
18
- // window.addEventListener('click', e => {
19
- // if (e.target.tagName === 'A') {
20
- // e.preventDefault()
21
- // if (e.target.href && e.target.href.indexOf(location.host)) {
22
- // history.pushState(null, '', e.target.href)
23
- // }
24
- // }
25
- // })
18
+ window . addEventListener (
19
+ 'click' ,
20
+ ( e ) => {
21
+ if ( e . target . tagName === 'A' ) {
22
+ const { href, target } = e . target
23
+ if (
24
+ target !== `_blank` &&
25
+ href . startsWith ( `${ location . protocol } //${ location . host } ` )
26
+ ) {
27
+ e . preventDefault ( )
28
+ // TODO save scroll position
29
+ history . pushState ( null , '' , href )
30
+ path . value = location . pathname
31
+ }
32
+ }
33
+ } ,
34
+ { capture : true }
35
+ )
36
+
37
+ window . addEventListener ( 'popstate' , ( e ) => {
38
+ // TODO restore scroll position
39
+ path . value = location . pathname
40
+ } )
26
41
27
42
provide ( PathSymbol , path )
28
43
@@ -40,16 +55,15 @@ const Content = {
40
55
watchEffect ( ( ) => {
41
56
let pagePath = path . value . replace ( / \. h t m l $ / , '' )
42
57
if ( pagePath . endsWith ( '/' ) ) {
43
- pagePath += 'index.md'
44
- } else {
45
- pagePath += '.md'
58
+ pagePath += 'index'
46
59
}
47
60
48
- import ( pagePath )
61
+ // awlays force re-fetch content in dev
62
+ import ( `${ pagePath } .md?t=${ Date . now ( ) } ` )
49
63
. then ( ( m ) => {
50
64
comp . value = m . default
51
65
} )
52
- . catch ( err => {
66
+ . catch ( ( err ) => {
53
67
comp . value = Default404
54
68
} )
55
69
} )
0 commit comments