11<template >
2+  <!--  https://www.cnblogs.com/mmzuo-798/p/10712009.html --> 
23 <div  class =" vue-route-transition" 
4+  <!--  需keep-alive --> 
35 <transition  :name =" state.pageDirection" @leave =" setRouterMap" 
6+  <keep-alive >
7+  <router-view 
8+  v-if =" keepAlive === true && $route.meta.keepAlive !== false" 
9+  ></router-view >
10+  </keep-alive >
11+  </transition >
12+  <!--  无需keep-alive --> 
13+  <transition  :name =" state.pageDirection" @leave =" setRouterMap" 
14+  <router-view 
15+  v-if =" keepAlive === false || $route.meta.keepAlive === false" 
16+  ></router-view >
17+  </transition >
18+  <!--  <transition :name="state.pageDirection" @leave="setRouterMap">
419 <keep-alive 
520 v-if="this.keepAlive === true && $route.meta.keepAlive !== false" 
621 > 
7-  <router-view ></router-view >
22+  <router-view 
23+  v-if="this.keepAlive === true && $route.meta.keepAlive !== false" 
24+  ></router-view> 
825 </keep-alive> 
926 <router-view v-else></router-view> 
10-  </transition >
27+  </transition>-->  
1128 </div >
1229</template >
1330<script >
31+ //  全局的
1432var  localSessionRouteChain =  sessionStorage .getItem (" $$routeChain" ||  [];
15- 
1633export  default  {
1734 name:  " vue-route-transition"  
1835 props:  { 
@@ -25,7 +42,9 @@ export default {
2542 try  { 
2643 localSessionRouteChain =  
2744 this .$route .path  !==  " /" ?  JSON .parse (localSessionRouteChain) :  []; 
45+  console .log (" 6666"  
2846 } catch  (error) { 
47+  console .log (" 8888"  
2948 localSessionRouteChain =  []; 
3049 } 
3150 return  { 
@@ -39,23 +58,29 @@ export default {
3958 }, 
4059 methods:  { 
4160 addRouteChain (route ) { 
61+  console .log (" addRouteChain - " this .state .addCount ); 
62+  console .log (" addRouteChain - " localSessionRouteChain .length ); 
4263 if  (this .state .addCount  ===  0  &&  localSessionRouteChain .length  >  0 ) { 
4364 //  排除刷新的时候 
4465 this .state .addCount  =  1 ; 
66+  console .log (" 哭泣哭泣"  
4567 } else  { 
4668 if  ( 
69+  this .state .addCount  ===  0  ||  
4770 (this .state .addCount  !==  0  &&  
4871 this .state .routeChain [this .state .routeChain .length  -  1 ].path  !==  
49-  route .path ) ||  
50-  this .state .addCount  ===  0  
72+  route .path ) 
5173 ) { 
74+  //  入栈 
5275 this .state .routeChain .push ({ 
5376 path:  route .path  
5477 }); 
78+  //  存储 
5579 sessionStorage .setItem ( 
5680 " $$routeChain"  
5781 JSON .stringify (this .state .routeChain ) 
5882 ); 
83+  //  添加数 
5984 this .state .addCount ++ ; 
6085 } 
6186 } 
@@ -73,6 +98,7 @@ export default {
7398 this .state .routerMap [" from" =  from .path ; 
7499 }, 
75100 setRouterMap () { 
101+  console .log (" 🐴setRouterMap" this .$route ); 
76102 let  dir =  this .state .pageDirection ; 
77103 let  to =  this .state .routerMap .to .replace (/ \/ / g" _"  
78104 let  from =  this .state .routerMap .from .replace (/ \/ / g" _"  
@@ -82,9 +108,11 @@ export default {
82108 try  { 
83109 if  (dir ===  " slide-left"  
84110 //  进入 
111+  console .log (" 进入"  
85112 this .state .routerMap [from] =  document .getElementById (from).scrollTop ; 
86113 } else  if  (dir ===  " slide-right"  
87114 //  返回 
115+  console .log (" 返回"  
88116 if  (this .keepAlive  ===  true  &&  this .$route .meta .keepAlive  !==  false ) { 
89117 document .getElementById (to).scrollTop  =  this .state .routerMap [to]; 
90118 } 
@@ -94,40 +122,59 @@ export default {
94122 } 
95123 }, 
96124 mounted () { 
125+  console .log (" vue-route-transition"  
97126 this .$router .beforeEach ((to , from , next ) =>  { 
98127 console .log (" 🐴beforeEach"  
99128 console .log (to); 
100129 console .log (from); 
101130
102131 //  定义一个可以记录路由路径变化的数据,这里用sessionStorage,或者在window.routeChain等变量 
103132 let  routeLength =  this .state .routeChain .length ; 
133+ 
134+  console .log (" routeLength -- "  
135+  console .log (" state.addCount -- " this .state .addCount ); 
104136 if  (routeLength ===  0  ||  this .state .addCount  ===  0 ) { 
137+  console .log (" 🔥-1"  
105138 this .setPageDirection ({ dir:  " slide-left"  
106139 this .addRouteChain (from); 
107140 this .addRouteChain (to); 
108141 } else  if  (routeLength ===  1 ) { 
142+  console .log (" 🔥-2"  
109143 this .setPageDirection ({ dir:  " slide-left"  
110144 this .addRouteChain (to); 
111145 } else  { 
146+  console .log (" 🔥-3"  
112147 let  lastBeforeRoute =  this .state .routeChain [routeLength -  2 ]; 
113148 if  (lastBeforeRoute .path  ===  to .path  &&  to .meta .slideLeft  !==  true ) { 
149+  console .log (" 🔥-4"  
114150 this .popRouteChain (); 
115151 this .setPageDirection ({ dir:  " slide-right"  
116152 } else  { 
153+  console .log (" 🔥-5"  
117154 this .addRouteChain (to); 
118155 this .setPageDirection ({ dir:  " slide-left"  
119156 } 
120157 } 
158+  console .log (" 🔥😪🔥"  
159+  console .log (this .state ); 
121160 next (); 
122161 }); 
123162 }, 
163+  created () { 
164+  console .log (" created😁😁😁 " this .$route .meta ); 
165+  console .log (" created😁😁😁 " this .state ); 
166+  }, 
124167 activated () { 
125-  console .log (" 😁😁😁 " +  this .state ); 
168+  console .log (" activated😁😁😁 " this .$route .meta ); 
169+  console .log (" activated😁😁😁 " this .state ); 
126170 } 
127171}; 
128172</script >
129173
130- <style  lang="less">
174+ <style  scoped></style >
175+ 176+ <style  scoped>
177+ /*  子绝父相 */ 
131178.vue-route-transition  {
132179 position absolute ; 
133180 width 100%  ; 
@@ -138,6 +185,7 @@ export default {
138185 backface-visibility hidden ; 
139186 perspective 1000 ; 
140187} 
188+ 
141189.fade-enter-active  {
142190 animation 400ms   forwards ; 
143191} 
@@ -149,32 +197,28 @@ export default {
149197 opacity 1 ; 
150198 } 
151199} 
152- /* 路由前进,退出*/ 
153- 
154- .slide-left-leave-active  {
155-  animation : pageFromCenterToLeft 400ms   forwards ; 
156-  z-index : 1 ; 
157- } 
158200
159201/* 路由后退,进入*/ 
160- 
161202.slide-right-enter-active  {
162-  animation : pageFromLeftToCenter 400 ms forwards ; 
203+  animation 2000 ms forwards ; 
163204 z-index 1 ; 
164205} 
165206
166207/* 路由后退,退出*/ 
167- 
168208.slide-right-leave-active  {
169-  animation : pageFromCenterToRight 400 ms forwards ; 
209+  animation 2000 ms forwards ; 
170210 z-index 10 ; 
171211 box-shadow -3px   0  5px   rgba (0 , 0 , 0 , 0.1 ); 
172212} 
173213
214+ /* 路由前进,退出*/ 
215+ .slide-left-leave-active  {
216+  animation 2000ms   forwards ; 
217+  z-index 9 ; 
218+ } 
174219/* 路由前进,进入*/ 
175- 
176220.slide-left-enter-active  {
177-  animation : pageFromRightToCenter 400 ms forwards ; 
221+  animation 2000 ms forwards ; 
178222 z-index 10 ; 
179223 box-shadow -3px   0  5px   rgba (0 , 0 , 0 , 0.1 ); 
180224} 
@@ -197,7 +241,6 @@ export default {
197241} 
198242
199243/* 路由前进,退出*/ 
200- 
201244@keyframes  pageFromCenterToLeft  {
202245 from  { 
203246 opacity 1 ; 
0 commit comments