尝试使某些路由需要身份验证。
我有这个:
class App extends Component {
render() {
const menuClass = `${this.props.contentMenuClass} col-xs-12 col-md-9`;
return (
<BrowserRouter history={browserHistory}>
<div className="App">
<Header properties={this.props} />
<div className="container-fluid">
<div className="row">
<SideNav />
<div className={menuClass} id="mainContent">
<Switch>
{routes.map(prop =>
(
<Route
path={prop.path}
component={prop.component}
key={prop.id}
render={() => (
!AuthenticationService.IsAutheenticated() ?
<Redirect to="/Login"/>
:
<Route path={prop.path}
component={prop.component}
key={prop.id}/>
)}
/>
))}
</Switch>
</div>
</div>
</div>
{/* <Footer /> */}
</div>
</BrowserRouter>
);
}
}
const mapStateToProps = state => ({
contentMenuClass: state.menu,
});
export default connect(mapStateToProps)(App);
注意:是的,身份验证服务可以正常工作。
对于每条路线,我都在检查用户是否经过身份验证,如果没有,那么我想将他们重定向到登录页面,如果是,那么它将以“/”的路线登陆第一页。
我得到的是:
react-dom.development.js:14227 The above error occurred in the <Route> component: in Route (created by App) in Switch (created by App) in div (created by App) in div (created by App) in div (created by App) in div (created by App) in Router (created by BrowserRouter) in BrowserRouter (created by App) in App (created by Connect(App)) in Connect(App) in Provider
我哪里做错了?