react-navigation-props-helper
安装
yarn add react-navigation-props-helper 或 npm install --save react-navigation-props-helper
怎么使用?
NavigatorPush
1、跳转路由:NavigatorPush.navigate('TestPage', {userName:'userName', pwd:'pwd'}); //跳转路由
2、回退路由:NavigatorPush.goBack();
3、设置参数:NavigatorPush.setParameters({test:{key:'value'}}); //当前路由设置参数
; { return <View style=stylescontainer> <RootView ref= { NavigatorPush; }/> //保存navigator的引用 /*<VideoPlayScreen url={'http://vodstztfqk4.vod.126.net/vodstztfqk4/3c901b47-0fc0-4490-9c2d-76b13465d4c4.mp4'}/>*/ </View> ; }
withMappedNavigationProps
;;; @withMappedNavigationProps@observer { NavigatorPush; //当前路由设置参数 console; } { const userName pwdtestnavigation = thisprops; console; return <View style=flex:1> <StatusBar hidden=false barStyle='dark-content' translucent=false backgroundColor='white'/> </View> ; }
routeInterceptor
拦截路由,比如某些页面需要登录才可以访问
NavigatorPush { if needLoginPage !== -1 NavigatorPush; return false; console; return true;};
说明须知
如果你使用了mobx的observer注解,解决办法就是把@observer放下面,以免mobx失效; react-navigation版本3.0.0以上。