@@ -99,6 +99,8 @@ function update(state,action){
9999 return inject ( state , action , props , state . scenes ) ;
100100}
101101
102+ var _uniqPush = 0 ;
103+
102104function reducer ( { initialState, scenes} ) {
103105 assert ( initialState , "initialState should not be null" ) ;
104106 assert ( initialState . key , "initialState.key should not be null" ) ;
@@ -110,7 +112,17 @@ function reducer({initialState, scenes}){
110112 assert ( state . scenes , "state.scenes is missed" ) ;
111113
112114 if ( action . key ) {
113- assert ( state . scenes [ action . key ] , "missed route data for key=" + action . key ) ;
115+ let scene = state . scenes [ action . key ] ;
116+ assert ( scene , "missed route data for key=" + action . key ) ;
117+
118+ // clone scene
119+ if ( action . type === PUSH_ACTION && scene . clone ) {
120+ let uniqKey = `${ _uniqPush ++ } $${ scene . key } ` ;
121+ let clone = { ...scene , key : uniqKey , sceneKey : uniqKey , parent : getCurrent ( state ) . parent } ;
122+ state . scenes [ uniqKey ] = clone ;
123+ action . key = uniqKey ;
124+ }
125+
114126 } else {
115127 // set current route for pop action or refresh action
116128 if ( action . type === POP_ACTION || action . type === POP_ACTION2 || action . type === REFRESH_ACTION ) {
@@ -127,7 +139,13 @@ function reducer({initialState, scenes}){
127139 assert ( el , "Cannot find element for parent=" + el . parent + " within current state" ) ;
128140 }
129141 action . parent = el . sceneKey ;
130- }
142+ }
143+
144+ // remove if clone
145+ if ( action . clone && action . sceneKey && ( action . type === POP_ACTION || action . type === POP_ACTION2 ) ) {
146+ delete state . scenes [ action . sceneKey ] ;
147+ }
148+
131149 }
132150 switch ( action . type ) {
133151 case POP_ACTION2 :
0 commit comments