React router native error, Unexpected Token

473 views Asked by At
import { StatusBar } from "expo-status-bar";
import React from "react";
import { StyleSheet, Text, View } from "react-native";
import Login from "./components/Login";
import Home from "./components/Home";
import { NativeRouter, Switch, Route, Link } from "react-router-native";
im;
export default class App extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      user: {},
    };
  }
  componentDidMount() {
    this.authListener();
  }
  authListener() {
    fire.auth().onAuthStateChanged((user) => {
      if (user) {
        this.setState({ user });
      } else {
        this.setState({ user: null });
      }
    });
  }
  render() {
    return (
      <NativeRouter>
        <View style={styles.container}>
          <Switch>
            <Route exact path="/">
              {this.state.user ? <h1><Home/></h1> : <h1><Login/></h1>}
            </Route>
          </Switch>
        </View>
      </NativeRouter>
    );
  }
}

**In the above code, I'm using firebase authentication. And if the user is logged in then i need the app to be routed to app component else, the app to be routed to Login component. And I'm using react-router-native as npm package to route here. But I'm getting error as "D:/csearch-client/csearch-client/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 <MemoryRouter {...props} />; | } |"**

1

There are 1 answers

5
Giovanni Esposito On

Ciao, I think you could do something like this:

      import Login from 'path/to/Login';
      import Home from 'path/to/Home';
      ...
      <Switch>
        <NativeRouter exact path="/" component={this.state.user ? Home : Login}>
        </NativeRouter>
      </Switch>