diff --git a/ExRouter.js b/ExRouter.js index 0a0b94561..303de0b19 100644 --- a/ExRouter.js +++ b/ExRouter.js @@ -155,6 +155,7 @@ export default class ExRouter extends React.Component { this.onPush = this.onPush.bind(this); this.onPop = this.onPop.bind(this); this.onPush = this.onPush.bind(this); + this.onReset = this.onReset.bind(this); this.onReplace = this.onReplace.bind(this); this.onJump = this.onJump.bind(this); } @@ -182,6 +183,22 @@ export default class ExRouter extends React.Component { return true; } + /*** + * Reset every scene with an array of routes + * @param route defined route + */ + + onReset(route: Route, props:{ [key: string]: any}):boolean { + if (this.props.onReset){ + const res = this.props.onReset(route, props); + if (!res){ + return false; + } + } + this.refs.nav.immediatelyResetRouteStack([new ExRouteAdapter(route, props)]); + return true; + } + onJump(route: Route, props:{ [key: string]: any}):boolean { if (this.props.onJump){ const res = this.props.onJump(route, props); diff --git a/Router.js b/Router.js index 2b70afba6..623c87a8a 100644 --- a/Router.js +++ b/Router.js @@ -20,6 +20,9 @@ export class RouterDelegate { onReplace(name:string, props:{ [key: string]: any}):boolean { return true; } + onReset(name:string, props:{ [key: string]: any}):boolean { + return true; + } onSwitch(name:string, props:{ [key: string]: any}):boolean { return true; } @@ -166,6 +169,13 @@ export default class Router { _replace(name:string, props:{ [key: string]: any} ) { this._stack[this._stack.length - 1] = name; } + /*** + * Reset every scene with an array of routes + * @param route defined route + */ + _reset(name:string, props:{ [key: string]: any} ) { + this._stack = [name]; + } _jump(name:string, props:{ [key: string]: any} ) { if (this._stack.indexOf(name) != -1){