在下面的代码中,路由更改为“ /”(通过history.push("/")
)后,Register组件仍停留在页面上。但是,如果我随后刷新页面,该页面将消失,并且一切看起来都应该如此。任何想法为什么会这样?
<Router>
<React.Fragment>
<Route
path="/register"
exact
render={() => <Register register={this.register} />}
/>
<Route
path="/"
exact
render={() => (
<Main
posts={posts}
post={post}
preview={preview}
/>
)}
/>
</React.Fragment>
</Router>
这是负责推送到根路由的注册方法:
register = (e, credentials) => {
e.preventDefault();
if (authEmails.includes(credentials.email)) {
rxcInit
.auth()
.createUserWithEmailAndPassword(credentials.email, credentials.password)
.then(() => {
history.push("/");
})
.catch(error => {
var errorMessage = error.message;
console.log(errorMessage);
this.setState({ modalShowing: true, errorMsg: errorMessage });
});
} else {
this.setState({
modalShowing: true,
errorMsg:
"That email address isn't authorized."
});
}
};