我正在使用Firebase,React和Redux构建Todo Web应用程序。所以,我有保护rotes如"/todos/add","/dashboard"客人路线为"/","/signup","/login"至极不能是接取,如果你进行身份验证。我的问题是,当我在"/todos/add"路由中通过身份验证时,我重新加载了应用程序重新加载的页面,并且调度了我的auth操作,将我的用户放置在redux存储中,但是我重定向到"/login"then到"/dashboard"。但我想在重新加载之前在同一页面上。我的代码:
PrivateRoute.js
import React from "react";
import { connect } from "react-redux";
import { Route, Redirect } from "react-router-dom";
import PropTypes from "prop-types";
const PrivateRoute = ({
isAuthenticated,
isLoading,
component: Component,
...rest
}) => (
<Route
{...rest}
render={props =>
isAuthenticated ? (
<Component {...props} {...rest} />
) : (
<Redirect to="/login" />
)
}
/>
);
const mapStateToProps = state => ({
isAuthenticated: …Run Code Online (Sandbox Code Playgroud) reactjs react-router firebase-authentication react-redux react-router-v4