Routing stacks
Const Navigator = stacknavigator ({
Setting: {screen:settingscreenview},
...
});
1. Set Routing status Change Intercept
function Getcurrentroutename (navigationstate) {
if (!navigationstate) {
return null;
}
Const route = Navigationstate.routes[navigationstate.index];
Dive into nested navigators
if (route.routes) {
return getcurrentroutename (route);
}
return route.routename;
}
Class Startscreen extends Component {
render () {
const prefix = Platform.os = = ' Android '? ' xx://aa/': ' xx://';
Return (
<navigator uriprefix={prefix}
onnavigationstatechange={
(prevstate, currentstate) = {
Const Currentscene = getcurrentroutename (currentstate);
if (Currentscene = = ' Setting ') {
//To do something
}
}
/>);
}
2. Login Jump Intercept
The route to intercept logins is const NEEDLOGINROUTE = [' Setting '];
Const Defaultgetstateforaction = StartScreen.router.getStateForAction;
StartScreen.router.getStateForAction = (action, state) + = {Let RouteName = Dealmsgdeal (action.routename); Intercept needs to log in after the jump is also not if (action.routename = = = RouteName && IsLogin = = False) {this.routes = [...]
. state.routes, {key: ' id-' +date.now (), RouteName: ' Login ', params: {name:routename, params:action.params}},
];
Return {... state, routes, Index:this.routes.length-1,};
} return Defaultgetstateforaction (action, state);
};
Required to intercept login page function dealmsgdeal (routeName) {Let theroutename = '; if (RouteName) {for (var i in Needloginroute) {if (needloginroute[i] = = routeName) {T
Heroutename = RouteName;
Break
}}} return theroutename; }