Skip to content

Commit

Permalink
Merge pull request #249 from JackWink/master
Browse files Browse the repository at this point in the history
Fix pop handling for multi-pop situations
  • Loading branch information
Pavlo Aksonov committed Mar 1, 2016
2 parents 7d25ed2 + 6f9d133 commit e9fa562
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
50 changes: 21 additions & 29 deletions Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,39 +126,31 @@ class Actions {
if (!this.currentRouter){
throw new Error("No current router is set");
}
if (num > 1){
for (let i=0;i<num;i++){
if (!this.pop()){
return false;
}
}
return true;
} else {
let router: BaseRouter = this.currentRouter;
debug("Pop, router="+router.name+" stack length:"+router.stack.length);
debug("Current route="+router.currentRoute.name+" type="+router.currentRoute.type);
while (router.stack.length <= 1 || router.currentRoute.type === 'switch'){
if (router.parentRoute) {
router = router.parentRoute.parent;
debug("Switching to parent router="+router.name);
} else {
break;
}

let router: BaseRouter = this.currentRouter;
debug("Pop, router="+router.name+" stack length:"+router.stack.length);
debug("Current route="+router.currentRoute.name+" type="+router.currentRoute.type);
while (router.stack.length <= 1 || router.currentRoute.type === 'switch'){
if (router.parentRoute) {
router = router.parentRoute.parent;
debug("Switching to parent router="+router.name);
} else {
break;
}
}
if (router.delegate.props && router.delegate.props.dispatch){
router.delegate.props.dispatch({...props, type: BEFORE_POP, route:router.currentRoute, name:router.currentRoute.name})
}
if (router.pop(num, props)){
this.currentRouter = router;
if (router.delegate.props && router.delegate.props.dispatch){
router.delegate.props.dispatch({...props, type: BEFORE_POP, route:router.currentRoute, name:router.currentRoute.name})
}
if (router.pop(1, props)){
this.currentRouter = router;
if (router.delegate.props && router.delegate.props.dispatch){
router.delegate.props.dispatch({...props, type: AFTER_POP, route:router.currentRoute, name:router.currentRoute.name})
}
return true;
} else {
return false;
router.delegate.props.dispatch({...props, type: AFTER_POP, route:router.currentRoute, name:router.currentRoute.name})
}

return true;
} else {
return false;
}

}
}
const actions = new Actions();
Expand Down
7 changes: 6 additions & 1 deletion ExRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,12 @@ export default class ExRouter extends React.Component {
return false;
}
}
this.refs.nav.pop();

if (num === 1) {
this.refs.nav.pop();
} else {
this.refs.nav.popBack(num);
}
return true;
}

Expand Down

0 comments on commit e9fa562

Please sign in to comment.