**请注意,这是在React类组件中
DefaultContainer = () => {
return (
<div className="app_container">
<SideNav />
<TopBar />
<Route exact path="/" component={Home} />
<Route path="/recent" component={Recent} />
<Route path="/AddNote" component={AddNote} />
<Route path="/ToDo" component={ToDo} />
</div>
);
};
// Check for authenticaition
AuthRoute = ({ component: Component, ...rest }) => {
return (
<Route
{...rest}
render={props => {
if (this.props.isAuthenticated) {
return <Component {...props} />;
}
else {
return (
<Redirect
to={{
pathname: "/login",
state: { from: props.location }
}}
/>
);
}
}}
/>
);
};
render() {
return (
<BrowserRouter>
<Switch>
<Route exact path="/login" component={this.LogInContainer} />
<Route exact path="/register" component={this.RegisterContainer} />
<this.AuthRoute component={this.DefaultContainer} />
</Switch>
</BrowserRouter>
);
}
}
我登录时,this.props.isAuthenticated设置为true。当我尝试访问“ /”路由时,我被重定向回登录名吗?但是this.props.isAuthenticated在React Dev工具中是真的吗?无法掌握问题所在。
答案 0 :(得分:0)
应该像这样简单:
Map<String, Foo> map = fooSet.stream().collect(toMap(Foo::getKey, identity()));