react< route> route/> react< route/gt; react< react> exement属性和组件属性之间有什么区别标签
案例1:在路由标签
const App = () => {
return(
<Routes>
<Route path="/" element={<Home />} />
<Route path="/album" element={<Album />} />
</Routes>
)
};
案例2中使用元素属性时:在路由中使用组件属性时
const App = () => {
return(
<Routes>
<Route path="/" component={<Home />} />
<Route path="/album" component={<Album />} />
</Routes>
)
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
React-Router的当前文档说,所有选项基本上都在做同样的事情,但是它们会留下它们以支持支持旧版本,但是您只能使用其中之一。
The current documentation of react-router says all there options basically does the same thing, but they leave them in order to Support older versions, but you can only use one of those.
您可能正在使用等于或大于v5.1 的版本,
根据迁移文档,您可以在任何地方安全地使用
元素
。“如果您首先升级到v5.1。在v5.1中,我们对v5.1进行了反应路由器v6会更容易。我们对处理元素的处理释放了增强功能,这些元素将有助于平滑过渡到v6。而不是使用和道具,只需在各处使用常规元素即可使用钩子访问路由器的内部状态。“
You are probably using a version equal to or greater than v5.1
According to migration documentation, you can use
element
safely everywhere."It will be easier to make the switch to React Router v6 if you upgrade to v5.1 first. In v5.1, we released an enhancement to the handling of elements that will help smooth the transition to v6. Instead of using and props, just use regular element everywhere and use hooks to access the router's internal state."
情况1:在路由标签中使用元素属性时,您必须在tag.ex中指定组件名称:( element = {&lt; .../&gt;})。
情况2:在路由标签中使用组件属性时,您可以在卷曲括号中写下组件名称,而不需要添加tag.ex.ex :( component = {...})。
Case 1: when using element attribute within Route tag, you have to specify your component name within tag.ex:(element={<.../>}).
Case 2: when using component attribute within Route tag, you can simply write your component name in curly braces doesn't need to add tag.ex:(component={...}).
元素和组件属性之间的主要衍射;
首先:如果您升级到v5.1,则更容易地进行反应路由器V6。
第二:元素属性给出了使用道具的oppurtunity,但是在组件属性中,您不能使用。
The main diffrences between element and component attributes;
First:It will be easier to make the switch to React Router v6 if you upgrade to v5.1
Second:element attribute gives oppurtunity to use props but in component attribute you cant.