Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
620 views
in Technique[技术] by (71.8m points)

react-router-native, NativeRouter.js Module parse failed - unexpected token

I'm getting an unexpected token error while using react native router. Expo is being used to render the page in my browser. I'm really new to React and React Native, so I'm kind of shooting in the dark with everything that I do to fix this. I found a similar issue (Failed to compile ./node_modules/react-router-native/NativeRouter.js #5684 https://github.com/ReactTraining/react-router/issues/5684), but the link that supposedly fixed the issue didn't work. This is the error that I'm getting:

/node_modules/react-router-native/NativeRouter.js 11:9 Module parse failed: Unexpected token (11:9) You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders

| */ | function NativeRouter(props) {

return ; | } |

I made no changes to the packaged files, so I'm assuming that I've done something wrong with my code on the App.js file. My code for App.js is this:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { NativeRouter, Route, Link } from 'react-router-native';
import Login from './login';
import Dashboard from './dashboard';
import Home from './home';



function App() {
  return (
    <div>
<NativeRouter>
    <View style={styles.container}>
      <View style={styles.nav}>
        <Link to="/" underlayColor="#f0f4f7" style={styles.navItem}>
          <Text>Home</Text>
        </Link>
        <Link
          to="/Login"
          underlayColor="#f0f4f7"
          style={styles.navItem}
        >
          <Text>Login</Text>
        </Link>
        <Link
          to="/Dashboard"
          underlayColor="#f0f4f7"
          style={styles.navItem}
        >
          <Text>Dashboard</Text>
        </Link>
      </View>

      <Route exact path="/" component={Home} />
      <Route path="/login" component={Login} />
      <Route path="/dashboard" component={Dashboard} />
    </View>
  </NativeRouter>

    </div>
  );
}

export default App;

My expected result would be to see the Nav bar render properly instead of getting the unexpected token error.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've answered my own question! I was installing react-navigation into the global project folder instead of in the front end directory where it was supposed to run. Now, it works great!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...