我有一个Login
屏幕。当我按下蓝色文本时,我希望它导航到Register
屏幕。
但是,它始终显示相同的Syntax Error: Unexpected Token
。
import React, { Component } from 'react';
import {
ScrollView,
Text,
TextInput,
View,
Button
} from 'react-native';
import { StackNavigator } from 'react-navigation';
import Register from './src/screens/Register';
export default class Login extends Component {
static navigationOptions = {
title: 'Welcome',
}
navigateToRegister = () => {
this.props.navigation.navigate('Register');
}
render() {
return (
<ScrollView style={{padding: 20}}>
<Text
style={{fontSize: 27}}>
Login
</Text>
<TextInput placeholder='Username' />
<TextInput placeholder='Password' />
<View style={{margin:7}} />
<Button
onPress={this.props.onLoginPress}
title="Submit"
/>
<Text style={{color: 'blue'}}
onPress={ this._navigateToRegister }
Register
</Text>
</ScrollView>
);
}
}
const App = StackNavigator({
Login: { screen: Login },
Register: { screen: Register },
Secured: { screen: Secured },
});
AppRegistry.registerComponent('App', () => App);
答案 0 :(得分:1)
您在代码中遇到语法错误。
倒数第二个文字没有结束尖括号
>
import React, { Component } from "react";
import { ScrollView, Text, TextInput, View, Button } from "react-native";
import { StackNavigator } from "react-navigation";
import Register from "./src/screens/Register";
export default class Login extends Component {
static navigationOptions = {
title: "Welcome"
};
navigateToRegister = () => {
this.props.navigation.navigate("Register");
};
render() {
return (
<ScrollView style={{ padding: 20 }}>
<Text style={{ fontSize: 27 }}>Login</Text>
<TextInput placeholder="Username" />
<TextInput placeholder="Password" />
<View style={{ margin: 7 }} />
<Button onPress={this.props.onLoginPress} title="Submit" />
<Text
style={{ color: "blue" }}
onPress={this._navigateToRegister}
Register
/>
</ScrollView>
);
}
}
const App = StackNavigator({
Login: { screen: Login },
Register: { screen: Register },
Secured: { screen: Secured }
});
AppRegistry.registerComponent("App", () => App);
你可以设置更漂亮和eslint他们将为你提供语法错误直白编辑代码,这样你就不需要花时间找到这种错误。 This is good guide to setup everything
答案 1 :(得分:0)
我遇到了代码中的错误
您已在onPress中使用this._navigateToRegister函数,并将navigateToRegister定义为函数。
您忘记关闭文字标记
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}