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

Is there a way to implement Stack Navigation inside view?

我正在为我的 class 创建一个基本的 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;

这不可能。您只能在导航器文件中创建 Stack.Navigator。 您在导航器文件中创建 Stack.Navigator,然后使用 this.props.navigation.navigate('Name of the screen you want to navigate').

调用要进入 Àccount 的屏幕

等待您的反馈 Thx :)。如有任何疑问,请随时提出。