@@ -97,6 +97,8 @@ function update(state,action){
9797 return inject ( state , action , props , state . scenes ) ;
9898}
9999
100+ var _uniqPush = 0 ;
101+
100102function reducer ( { initialState, scenes} ) {
101103 assert ( initialState , "initialState should not be null" ) ;
102104 assert ( initialState . key , "initialState.key should not be null" ) ;
@@ -108,7 +110,17 @@ function reducer({initialState, scenes}){
108110 assert ( state . scenes , "state.scenes is missed" ) ;
109111
110112 if ( action . key ) {
111- assert ( state . scenes [ action . key ] , "missed route data for key=" + action . key ) ;
113+ let scene = state . scenes [ action . key ] ;
114+ assert ( scene , "missed route data for key=" + action . key ) ;
115+
116+ // clone scene
117+ if ( action . type === PUSH_ACTION && scene . clone ) {
118+ let uniqKey = `${ _uniqPush ++ } $${ scene . key } ` ;
119+ let clone = { ...scene , key : uniqKey , sceneKey : uniqKey , parent : getCurrent ( state ) . parent } ;
120+ state . scenes [ uniqKey ] = clone ;
121+ action . key = uniqKey ;
122+ }
123+
112124 } else {
113125 // set current route for pop action or refresh action
114126 if ( action . type === POP_ACTION || action . type === POP_ACTION2 || action . type === REFRESH_ACTION ) {
@@ -125,7 +137,13 @@ function reducer({initialState, scenes}){
125137 assert ( el , "Cannot find element for parent=" + el . parent + " within current state" ) ;
126138 }
127139 action . parent = el . sceneKey ;
128- }
140+ }
141+
142+ // remove if clone
143+ if ( action . clone && action . sceneKey && ( action . type === POP_ACTION || action . type === POP_ACTION2 ) ) {
144+ delete state . scenes [ action . sceneKey ] ;
145+ }
146+
129147 }
130148 switch ( action . type ) {
131149 case POP_ACTION2 :
0 commit comments