Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs ReactRouter:无法读取属性“;imageId";未定义的_Reactjs_React Router - Fatal编程技术网

Reactjs ReactRouter:无法读取属性“;imageId";未定义的

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

我正在尝试将React路由器用于React本机项目。在我的index.js文件中,我有:

  <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>