【发布时间】:2017-08-09 06:39:11
【问题描述】:
我想在我的公共布局中渲染我的一些路线,在我的私人布局中渲染一些其他路线,有没有一种干净的方法可以做到这一点?
显然不起作用的示例,但我希望大致说明我在寻找什么:
<Router>
<PublicLayout>
<Switch>
<Route exact path="/" component={HomePage} />
<Route exact path="/about" component={AboutPage} />
</Switch>
</PublicLayout>
<PrivateLayout>
<Switch>
<Route exact path="/profile" component={ProfilePage} />
<Route exact path="/dashboard" component={DashboardPage} />
</Switch>
</PrivateLayout>
</Router>
我想要切换某些路由的布局,我该如何使用新的 react 路由器来做到这一点?
嵌套路由不再起作用并给我这个错误:
You should not use <Route component> and <Route children> in the same route; <Route children> will be ignored
编辑:让布局包裹整个路由组也意味着只要您留在同一个私有/公共路由组中,这些布局只会渲染一次。例如,如果您的布局必须从服务器获取某些内容,这将是一件大事,因为如果您使用布局包装每个页面,那么每次页面更改都会发生这种情况。
【问题讨论】:
-
你能找到一种干净的方法吗?
标签: reactjs react-router