我在实际的Redux文件中使用Firebase来验证我的用户。但是如何将他从登录页面重定向到另一个?
import firebase from '../app/firebase/firebase.js';
export const SIGN_IN = 'SIGN_IN'
export const GET_BOOKS = 'GET_BOOKS'
export const signInState = (email, password) => dispatch => {
firebase.auth()
.signInWithEmailAndPassword(email, password)
.then(() => {
dispatch({
type: 'SIGN_IN',
})
push("/home") /// here i try to redirect user
})
.catch((error) => {
console.log(error);
alert(error);
})
}
我的App文件中也有PrivateRoute。如何到达这条“路”?
<PrivateRoute
path="/home"
signedInStatus={this.props.signedInStatus}
component={Home} />}/>
答案 0 :(得分:0)
我刚刚使用了 Connected-React-Router
解决我的问题:
export const signInState = (email, password) => dispatch => {
firebase.auth()
.signInWithEmailAndPassword(email, password)
.then(() => {
dispatch({
type: 'SIGN_IN',
})
dispatch(push('/home')) /// <-----that was an answer
})