expo-router 将参数传递到打字稿类定义的页面

问题描述 投票:0回答:1

我使用 expo-routing 将一些参数传递到屏幕,但屏幕是类定义的组件,我如何获取参数? 当我记录道具时,我有这个:

{"segment": "home/index"}

屏幕#1

router.replace({ pathname: 'home', params: { id: '123' } });

屏幕#2

export default class HomePage extends React.Component<HomePagePropsType, HomePageStateType> {

    constructor( props: HomePagePropsType ) {
        super( props );
        console.log( this.props )
    }

typescript react-native routes expo expo-router
1个回答
0
投票

这是因为您需要使用

useLocalSearchParams
 中的 
expo-router

试试这个:

import { useLocalSearchParams } from 'expo-router'

const { id } = useLocalSearchParams();
© www.soinside.com 2019 - 2024. All rights reserved.