【问题标题】:Declaring React Native routes in child components not working在子组件中声明 React Native 路由不起作用
【发布时间】:2018-04-13 09:10:30
【问题描述】:

我在使用 react router v4 在 react native 中实现嵌套路由时遇到问题。

如果嵌套路由在 App.js 中声明它可以正常工作,但是当它在另一个组件中声明时,重定向不起作用。

我试图按照这里的文档:https://reacttraining.com/react-router/core/guides/philosophy/nested-routes

简单吗?

我创建了一个简单的 repo,其中包含要复制的所有代码:

  1. git clone https://github.com/814k31/TestReactNativeRoutingv4.git
  2. cd TestReactNativeRoutingv4
  3. npm install
  4. npm run <platform>

https://github.com/814k31/TestReactNativeRoutingv4

【问题讨论】:

标签: reactjs react-native routes nested react-router


【解决方案1】:

感谢 concord 上的反应人员

我需要使用相对链接,否则路由器会在根组件 (App.js) 中查找路由并且不知道嵌套路由。

const Tacos = ({ match }) => ( // here's a nested div <div> <Route exact path={`${match.url}/Carnitas`} // The "match.url" is critical here component={Carnitas} /> TACOS <Redirect to={`${match.url}/Carnitas`} push /> // And here </div> )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-02-06
    • 2022-09-22
    • 1970-01-01
    • 2016-12-29
    • 2020-05-21
    • 2021-02-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多