【问题标题】:react params - Warning: Unknown prop `params` on <a> tag. Remove this prop from the element反应参数 - 警告:<a> 标签上的未知道具`params`。从元素中移除这个道具
【发布时间】:2018-02-01 14:25:19
【问题描述】:

我正在尝试使用 react 路由器和 Warning: Unknown prop params on &lt;a&gt; tag. Remove this prop from the element. 创建个人资料页面我正在尝试将参数传递给路由,以便每个用户都有自己独特的页面加载他们的内容。我得到的解决方案是从 2015 年开始的,我不知道他们是否已将其删除。是否有将参数传递到路由路径的新/更新版本,或者我做错了什么?

<Route component={userProfile} path="/user/:userId" userIdentity={Meteor.userId()}/>

<p><Link to="/userProfile/:userId" params={{userId: Meteor.userId()}}>My Profile</Link></p>

【问题讨论】:

    标签: reactjs meteor parameters react-router


    【解决方案1】:

    你想这样做

    <Link to={`user/${Meteor.userId()}`} />
    

    即使用用户 ID 构造您要链接到的静态路由。没有比这更复杂的了。

    【讨论】:

    • 是否可以有一个多路径的 Route 渲染同一个组件?
    • 是的,您的问题&lt;Route path="user/:userId" /&gt; 中的路线中已经包含了它。我看不出接受的答案如何解决您的问题-您描述的警告发生是因为您已将不必要的params 参数传递给&lt;Link。无论如何,很高兴您的问题得到了解决!
    • 是的,你的确实对警告有所帮助,但对我的整个问题没有帮助
    【解决方案2】:

    您只是想将userId 作为参数传递吗?您可以通过调用this.props.match.params.userId 并从那里开始在您的Link'd 组件&lt;UserProfile /&gt; 中访问它。

    【讨论】:

    • 这对我不起作用。有人有解释或参考吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-05
    • 1970-01-01
    • 2017-03-11
    • 2017-06-17
    • 2017-06-21
    • 1970-01-01
    相关资源
    最近更新 更多