[英]Rendering a react component variable with react router v6
I am using react router v6 and I want to render a component stored in a variable.我正在使用 react router v6,我想渲染存储在变量中的组件。 In earlier versions of react router they have component props that allows you to render a component using a variable without the JSX syntax, however the V6 doesn't allow that.
在早期版本的 React Router 中,它们具有组件属性,允许您使用不使用 JSX 语法的变量来渲染组件,但是 V6 不允许这样做。
import ComponentName from "components/ComponentName"
...
const component = ComponentName;
...
<Router path="..." element={component } />
you can call your variable as a function您可以将变量称为 function
import ComponentName from "components/ComponentName"
...
const component = ComponentName;
...
<Router path="..." element={component()} />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.