我使用 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 )
}
这是因为您需要使用
useLocalSearchParams
中的
expo-router
试试这个:
import { useLocalSearchParams } from 'expo-router'
const { id } = useLocalSearchParams();