有没有办法在视图内实现堆栈导航?

Noo*_*239 3 navigation reactjs react-native

我正在为我的班级创建一个基本的 React Native 应用程序,但遇到了问题。我正在尝试在我的视图中实现堆栈导航,但由于某种原因它没有显示蓝色堆栈按钮。可以这样做吗?

import React,{Component} from 'react';
import {View, Text, StyleSheet, Image} from 'react-native';
import { createStackNavigator } from '@react-navigation/stack';
import Home from '../views/Home.js'

let stack = createStackNavigator();

class Account extends Component{
    render(){
        return(
            <View style = {styles.container} >
                <Text style = {styles.PageHeader}>TRENDZ</Text>
                <Text style = {styles.PageSubHeader}> Online Store</Text>
                <Image style = {styles.AccImage} source={require('../../assets/login/login.jpg')} {...this.props} />
                        <stack.Navigator>
                            <stack.Screen name = 'Home' component = {Home} />
                        </stack.Navigator>
            </View>
        )
    }
}

const styles = StyleSheet.create({
    container: {
        marginTop: 20,
    },
    AccImage: {
        height:600,
        width: null
    },
    PageHeader: {
        fontWeight: 'bold',
        fontSize: 70,
        textAlign: 'center',
        color: 'orange'
    },
    PageSubHeader: {
        textAlign: 'center',
        fontSize: 25,
        paddingBottom: 20
    }
})

export default Account;
Run Code Online (Sandbox Code Playgroud)

Gab*_*lva 5

那是不可能的。您只能Stack.Navigator在导航器文件中创建 。\n您Stack.Navigator在导航器文件中创建 ,然后使用 调用要进入的\xc3\x80ccount屏幕this.props.navigation.navigate('Name of the screen you want to navigate')

\n

等待您的反馈,谢谢:)。如有任何疑问,请随时询问。

\n

  • 不客气!它不起作用,因为组件``&lt;Stack.Navigator/&gt;```只能在您“注册”应用程序将具有的屏幕的组件中工作,通常您将`` `导航.容器```。您可以在React导航的[文档](https://reactnavigation.org/docs/hello-react-navigation)中查看更多详细信息。 (2认同)