Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,24 @@ class Actions {
}
return res;
}
pop(num: number = 1, props: { [key: string]: any} = {}){
pop(num: number = 1, props: { [key: string]: any} = {}, parentRouter: BaseRouter){
props = filterParam(props);
if (!isNumeric(num)){
num = 1;
}
if (!this.currentRouter){
throw new Error("No current router is set");

let router:BaseRouter;
if (parentRouter) {
router = parentRouter;
}

let router: BaseRouter = this.currentRouter;
else {
if (!this.currentRouter) {
throw new Error("No current router is set");
}

router = 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'){
Expand All @@ -142,7 +150,8 @@ class Actions {
router.delegate.props.dispatch({...props, type: BEFORE_POP, route:router.currentRoute, name:router.currentRoute.name})
}
if (router.pop(num, props)){
this.currentRouter = router;
if (!parentRouter)
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})
}
Expand Down
8 changes: 6 additions & 2 deletions Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*
*/

import Actions from './Actions';
import type BaseRouter from './BaseRouter';
export default class Route {
name: string;
Expand Down Expand Up @@ -41,7 +42,10 @@ export default class Route {
this.footer = footer;
this.props = props;
this.wrapRouter = wrapRouter || type=='switch';

this.pop = this.pop.bind(this)
}

}
pop(num: number = 1, props: { [key: string]: any} = {}) {
Actions.pop(num, props, this.parent);
}
}