react-router-native doesnt work

800 Views Asked by At

Error: undefined is not an object (evaluating '_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>

After click to Link displays an error. What's wrong?

1

There are 1 best solutions below

1
On

Try adding nativeHistory to your routes

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

<Router history={nativeHistory}>

</Router>