【问题标题】:React Router Native(4.3.0) Url Params break appReact Router Native(4.3.0) Url Params 中断应用程序
【发布时间】:2018-09-17 22:24:56
【问题描述】:

我有一个 React Native 项目,我正在使用 react-router-native 版本 4.3.0。

<Provider store={store}>
      <NativeRouter>
        <Base user={this.state.user} >
          <View style={styles.container}>
            <Route exact path="/" component={Splashstart}/>
            <Route exact path="/profile" component={Profile}/>
            <Route exact path="/report/:id" component={Report}/>
          </View>
        </Base>
      </NativeRouter>
    </Provider>

我将我的应用程序包装在一个基本组件中,该组件基本上决定它是否需要显示导航,如果有用户。

render() {
if(this.props.user) {
  return (
    <SafeAreaView style={styles.container}>
      <View style={styles.content}>
        {this.props.children}
      </View>
      <Nav />
    </SafeAreaView>
  );
} else {
  return (
    <View style={styles.container}>
      <View style={styles.content}>
        {this.props.children}
      </View>
    </View>
  );
}

}

当我点击报告路线时,导航变得毫无用处,我卡在页面中。它似乎破坏了我的路线。

如果它的 url (:id) 上有参数,它可以是任何路由。我尝试只渲染一段文本,但它仍然发生 - 所以我认为它不是页面中的任何内容。

我的&lt;Nav /&gt; 组件在每次页面刷新时都会重新渲染,就像基础一样,我希望基础也随着孩子的变化而变化,但导航不应该保留吗?

this.state.user 在传递给基础组件时不会改变。

任何帮助都是史诗般的!

干杯

【问题讨论】:

    标签: javascript reactjs react-native react-router react-router-v4


    【解决方案1】:

    我认为Route 组件有一个错字:额外的extract 属性。

    <Route exact path="/report/:id" component={Report}/>
    

    【讨论】:

    • 为响应干杯,虽然确切的道具只是意味着 /report 不会响应,但 report/:id 会。我试了一下并删除了它,但它没有修复它。
    • 抱歉回答错误。我对确切的道具有一个模糊的纪念品,结果证明我错了。您是否有机会添加报告组件的摘录?
    猜你喜欢
    • 2018-09-10
    • 1970-01-01
    • 2015-03-12
    • 2016-01-27
    • 2016-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多