[英]Uncaught Error: [RouteWrapper] is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>
[英]Layout is not a <Route> component. All component children of <Routes> must be a <Route> or <React.Fragment>. How should I overcome this error?
其他Route
组件是Route
组件的唯一有效子组件。 这是构建嵌套路由的用例。 对于路由内容/组件,这些必须使用element
属性。
将Layout
组件渲染为Route
组件的element
。
例子:
<Routes>
<Route
path='/'
element={(
<Layout>
<Home />
</Layout>
)}
/>
</Routes>
让布局组件为嵌套路由渲染一个Outlet
也很常见。
例子:
const Layout = () => (
<>
<Header />
<Outlet />
<Footer />
</>
);
...
<Routes>
<Route element={<Layout />}>
<Route path='/' element={<Home />} />
</Route>
</Routes>
您可以从那里提取<Home/>
组件,并将布局作为道具提供给 Route,就像这样
<Route component={Layout} />
并在自己的 Layout 组件中提供您的 home 组件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.