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

时间:2017-05-31 20:21:25

标签: reactjs react-router

我正在尝试将React Router用于反应原生项目。在我的index.js文件中,我有:

  <NativeRouter>
    <View>
      <Route path="/" component={MainComponent} />
      <Route path="/images/:imageId/" component={ShowImage} />
    </View>
  </NativeRouter>

在DisplayComponent中我有:

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

所以我猜测道具没有被传递但是无法弄清楚在哪里...感谢所有的帮助。

1 个答案:

答案 0 :(得分:0)

在我猜你正在使用的finalurl="https://example.com" req=requests.get(finalurl,verify=False,headers=hdrs) html=req.content html=html.decode('utf-8','ignore') if "&copy" in html: pos_c = html.find("&copy;") symbol = html[pos_c-100:pos_c+100] print(symbol) 的最新版本中,可以从react-router道具获得路线参数。所以为了获得match

使用

imageId