Reactjs ReactRouter:无法读取属性“;imageId";未定义的
我正在尝试将React路由器用于React本机项目。在我的index.js文件中,我有:Reactjs ReactRouter:无法读取属性“;imageId";未定义的,reactjs,react-router,Reactjs,React Router,我正在尝试将React路由器用于React本机项目。在我的index.js文件中,我有: <NativeRouter> <View> <Route path="/" component={MainComponent} /> <Route path="/images/:imageId/" component={ShowImage} /> </View> </NativeRouter&g
<NativeRouter>
<View>
<Route path="/" component={MainComponent} />
<Route path="/images/:imageId/" component={ShowImage} />
</View>
</NativeRouter>
所以我猜道具没有被传进来,但我不知道在哪里。。。谢谢你的帮助 在我猜您正在使用的最新版本的
react router
中,路由参数可从match
属性获得。因此,为了获得imageId
使用
{this.props.match.params.imageId}
当您看到错误时,页面的URL是什么?尝试将路由器中的路径更改为/images/:imageId
,并将链接到/images/7326
中的更改为,这是一个react原生应用程序,因此我不确定如何检查URL。。
<View}>
{items.map( item => {
return (
<Link to="images/7326" key={item.id}>
<Image
source={{uri: 'https://someImageLink...'}}
/>
</Link>
)
})}
</View>
export default class ShowImage extends Component {
render() {
return (
<View>
<Text>{this.props.params.imageId}</Text>
</View>
);
}
}
can not read "imageId" of undefined.
<Text>{this.props.match.params.imageId}</Text>