react-native 实现界面局部的路由跳转
版本
"react-navigation": "2.18.3"
"react-native": "0.62.2"
直接上代码
import React from 'react';
import {createStackNavigator} from 'react-navigation';
import {View} from 'react-native';
const MyStack = createStackNavigator(
{
Home: {screen: 引入的页面}, //首页
},
{
initialRouteName: 'Home',
headerMode: 'none',
},
);
class App extends React.Component {
static router = {
...MyStack.router,
getStateForAction: (action, lastState) => {
return MyStack.router.getStateForAction(action, lastState);
},
};
componentWillMount = async () => {
};
constructor(props) {
super(props);
this.state = {
};
}
componentWillUnmount() {
}
render() {
const {navigation} = this.props;
return (
<>
<View>头部区域</View>
<MyStack navigation={navigation}/>
<View>尾部区域</View>
</>
);
}
}
const styles = StyleSheet.create({
});
export default App;

本文展示了如何在React Native应用中利用react-navigation库进行界面的局部路由跳转。通过创建StackNavigator并配置初始路由,实现了在不改变全局导航状态的情况下,仅更新特定部分的界面。代码示例中,首页组件被导入并添加到路由栈中,同时设置了头部模式为none,确保了无头导航。在App组件的渲染方法中,头部、内容和尾部区域被分别渲染,通过传递navigation属性,实现在MyStack内的局部导航操作。
491

被折叠的 条评论
为什么被折叠?



