File tree 5 files changed +104
-5
lines changed
5 files changed +104
-5
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ <h1>Vue Router Examples</h1>
25
25
< li > < a href ="auth-flow "> Auth Flow</ a > </ li >
26
26
< li > < a href ="discrete-components "> Discrete Components</ a > </ li >
27
27
< li > < a href ="nested-router "> Nested Routers</ a > </ li >
28
+ < li > < a href ="keepalive-view "> Keepalive View</ a > </ li >
28
29
</ ul >
29
30
</ body >
30
31
</ html >
Original file line number Diff line number Diff line change
1
+ import Vue from 'vue'
2
+ import VueRouter from 'vue-router'
3
+
4
+ Vue . use ( VueRouter )
5
+
6
+ const Wrap = { template : '<div>child: <router-view></router-view></div>' }
7
+
8
+ const Index = {
9
+ template : '<wrap />' ,
10
+ components : {
11
+ Wrap
12
+ }
13
+ }
14
+
15
+ const IndexChild1 = { template : '<div class="current">index child1</div>' }
16
+ const IndexChild2 = { template : '<div class="current">index child2</div>' }
17
+
18
+ const Home = { template : '<div class="current">home</div>' }
19
+
20
+ const router = new VueRouter ( {
21
+ mode : 'history' ,
22
+ base : __dirname ,
23
+ routes : [
24
+ {
25
+ path : '/index' ,
26
+ component : Index ,
27
+ children : [
28
+ {
29
+ path : 'child1' ,
30
+ component : IndexChild1
31
+ } ,
32
+ {
33
+ path : 'child2' ,
34
+ component : IndexChild2
35
+ }
36
+ ]
37
+ } ,
38
+ {
39
+ path : '/home' ,
40
+ component : Home
41
+ }
42
+ ]
43
+ } )
44
+
45
+ new Vue ( {
46
+ router,
47
+ template : `
48
+ <div id="app">
49
+ <ul>
50
+ <li><router-link tag="a" to="/index/child1">index child 1</router-link></li>
51
+ <li><router-link tag="a" to="/index/child2">index child 2</router-link></li>
52
+ <li><router-link tag="a" to="/home">home</router-link></li>
53
+ </ul>
54
+ <keep-alive>
55
+ <router-view></router-view>
56
+ </keep-alive>
57
+ </div>
58
+ `
59
+ } ) . $mount ( '#app' )
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < link rel ="stylesheet " href ="/global.css ">
3
+ < style >
4
+ a .router-link-active , li .router-link-active a {
5
+ color : # f66 ;
6
+ }
7
+ a .router-link-exact-active , li .router-link-exact-active a {
8
+ border-bottom : 1px solid # f66 ;
9
+ }
10
+ </ style >
11
+ < a href ="/ "> ← Examples index</ a >
12
+ < div id ="app "> </ div >
13
+ < script src ="/__build__/shared.chunk.js "> </ script >
14
+ < script src ="/__build__/keepalive-view.js "> </ script >
Original file line number Diff line number Diff line change @@ -26,11 +26,14 @@ export default {
26
26
let depth = 0
27
27
let inactive = false
28
28
while ( parent && parent . _routerRoot !== parent ) {
29
- if ( parent . $vnode && parent . $vnode . data . routerView ) {
30
- depth ++
31
- }
32
- if ( parent . _inactive ) {
33
- inactive = true
29
+ const vnodeData = parent . $vnode && parent . $vnode . data
30
+ if ( vnodeData ) {
31
+ if ( vnodeData . routerView ) {
32
+ depth ++
33
+ }
34
+ if ( vnodeData . keepAlive && parent . _inactive ) {
35
+ inactive = true
36
+ }
34
37
}
35
38
parent = parent . $parent
36
39
}
Original file line number Diff line number Diff line change
1
+ module . exports = {
2
+ 'keepalive view' : function ( browser ) {
3
+ browser
4
+ . url ( 'http://localhost:8080/keepalive-view/' )
5
+ . waitForElementVisible ( '#app' , 1000 )
6
+ . assert . count ( 'li a' , 3 )
7
+
8
+ . click ( 'li:nth-child(1) a' )
9
+ . assert . containsText ( '.current' , 'index child1' )
10
+
11
+ . click ( 'li:nth-child(2) a' )
12
+ . assert . containsText ( '.current' , 'index child2' )
13
+
14
+ . click ( 'li:nth-child(3) a' )
15
+ . assert . containsText ( '.current' , 'home' )
16
+
17
+ // back to index child1 and check it
18
+ . click ( 'li:nth-child(1) a' )
19
+ . assert . containsText ( '.current' , 'index child1' )
20
+ . end ( )
21
+ }
22
+ }
You can’t perform that action at this time.
0 commit comments