'react router native - undefined is not an object

I've created a project using npx react-native init MyTestApp

When i use react-router-native i get an error. When i remove NativeRouter and Route components there is no error.

Repository

How i can fix this error?

index.js:

const Home = () => <Text>Home</Text>;
const About = () => <Text>About</Text>;
const App = () => (
  <NativeRouter>
    <View>
      <Text>Hello world</Text>
      <Link to="/about">
        <Text>About</Text>
      </Link>
      <Route exact path="/" component={Home} />
      <Route path="/about" component={About} />
    </View>
  </NativeRouter>
);

AppRegistry.registerComponent(appName, () => App);

package.json:

{
  "name": "mytestapp",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "17.0.2",
    "react-native": "0.68.2",
    "react-router-native": "^5.3.2"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "^7.32.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.67.0",
    "react-test-renderer": "17.0.2"
  },
  "jest": {
    "preset": "react-native"
  }
}

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source