简体   繁体   English

反应路由器本机错误,意外令牌

[英]React router native error, Unexpected Token

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. **在上面的代码中,我使用的是 firebase 身份验证。 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.我使用 react-router-native 作为 npm package 在这里路由。 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) {但是我收到错误消息“D:/csearch-client/csearch-client/node_modules/react-router-native/NativeRouter.js 11:9 Module parse failed: Unexpected token (11:9) You may need a proper loader为了处理这个文件类型,目前没有配置加载器来处理这个文件。参见https://webpack.js.org/concepts#loaders | */ | function NativeRouter(props) {

return <MemoryRouter {...props} />;返回 <MemoryRouter {...props} />; | | } |"** } |"**

Ciao, I think you could do something like this: Ciao,我认为你可以这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM