react-router-native不起作用

时间:2018-05-28 04:46:58

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

错误: undefined不是一个对象(评估'_this.context.router.history')

index.js:

          <Left>

              <Link to="/menu">
                <Image
                  source={require("./src/assets/images/home.png")}
                  style={styles.homeIcon}
                />
              </Link>
          </Left>
...
<NativeRouter>
          <Container>
            <Stack>
              <Route exact path="/" component={Login} />
              <Route
                path="/menu"
                component={() => <Menu showMenuIcon={this.showMenuIcon} />}
              />
              <Route
                path="/dialog"
                component={() => <Dialog showMenuIcon={this.showMenuIcon} />}
              />
              ...
            </Stack>
          </Container>
</NativeRouter>

点击链接后显示错误。怎么了?

1 个答案:

答案 0 :(得分:0)

尝试将nativeHistory添加到您的路线

import {nativeHistory} from 'react-router-native';

<Router history={nativeHistory}>

</Router>