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
add reset action
  • Loading branch information
daemonchen committed Jan 5, 2016
commit fba07a317c61e3fb93dad5f63ef2d8187a15b1f5
17 changes: 17 additions & 0 deletions ExRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 10 additions & 0 deletions Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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){
Expand Down