首先是我的路线:
const routes = (
<Route path="/" component={authWrapper(App)}>
<IndexRoute getComponent={resolveIndexComponent} />
<Route path="about" getComponent={resolveAboutComponent} />
</Route>
);
注意根路由如何用&#34; authWrapper&#34;包装,在那里我检查用户是否有JWT并派遣到redux存储结果。
问题/问题:如何加载不同的&#34;孩子&#34;用于经过身份验证和未经身份验证的用户进入IndexRoute时的组件?
上面的resolveIndexComponent只是加载&#39; / domains / home&#39;其中包含:
const mapStateToProps = (state) => ({ authenticated: state.common.currentUser });
const App = (props) => {
if (props.authenticated) {
return (<Authenticated />);
}
return (<Unauthenticated />);
};
export default connect(mapStateToProps)(App);
我可以跳过这个并直接从react-router加载<Authenticated />
或<Unauthenticated />
吗? (基于道具或甚至authWrapper返回的内容)