我有一个react 应用程序与2种不同的布局,"主布局"和"授权布局".我发现我的主布局页面工作没有问题,但它似乎没有加载授权布局页面.如果我try 访问"/login"
,我会得到一个空白的主布局页面,这让我认为它只访问了第一个<Route>
部分.
<div className="App">
<Provider store={store}>
<BrowserRouter>
<Switch>
<Route>
<MainLayout>
<Switch>
<Route path="/" exact component={Dashboard} />
<Route path="/search" exact component={SearchResults} />
<Route path="/user/:user_id" exact component={Profile} />
<PrivateRoute path="/settings" exact component={Settings} />
<Route
path="/communities"
exact
component={CommunityDashboard}
/>
<PrivateRoute
path="/communities/new"
exact
component={CommunityNew}
/>
<Route
path="/communities/view/:community_id"
exact
component={CommunityView}
/>
<PrivateRoute
path="/communities/edit/:community_id"
exact
component={CommunityEdit}
/>
<Route path='/404' component={Error404} />
</Switch>
</MainLayout>
</Route>
<Route>
<AuthLayout>
<Switch>
<Route
path="/password-reset/:reset_key?"
exact
component={PasswordReset}
/>
<Route path="/register" exact component={Register} />
<Route path="/login" exact component={Login} />
</Switch>
</AuthLayout>
</Route>
<Redirect from='*' to='/404' />
</Switch>
</BrowserRouter>
</Provider>
</div>
我知道Switch
将呈现匹配的第一个<Route>
,这可能是我的设置不起作用的原因.如何才能在不干扰已创建的路径的情况下渲染这两个布局?