javascript - 如何在网络上显示参数(React Js)

标签 javascript reactjs

我有以下js

App.js

<LayoutRoute
 exact
 path="/analysis/:id"
 layout={MainLayout}
 component={AnalysisPage}
/>

索引.js

<IconWidget
 title="companyA"
 subtitle="Top Product Trade: Pen"
 color="info"
 onClick={()=>{window.location='analysis/companyA'}}
/>

分析.js

function analysisPage({match}){
  console.log(match)
  return(
    <div>
    {"${match.params.id}"}
    </div>
  )
}
const AnalysisPage= () => {
  return(
   <div>
     Company: {this.analysisPage}
   </div>
export default AnalysisPage;

我在 App.js 中应用了 React Router,它可以通过按下按钮将网站从 index.js 重定向到 analysis.js。 但是,我想将参数显示到 div。我引用了 https://alligator.io/react/react-router-parameters但是,它不起作用。我想知道我做错了什么?非常感谢

最佳答案

你必须提供 Prop :

Company: {this.analysisPage(this.props)}

以便可以使用匹配参数:

function analysisPage({match}){

关于javascript - 如何在网络上显示参数(React Js),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52695303/

相关文章:

javascript - 函数返回 promise ,而不是值

javascript - 安装react-router-dom时遇到错误

php - 跨浏览器异步 uploader ?

javascript - 使用 JavaScript 访问框架的文档对象

javascript - 如何让我的 API 请求获取更新的数据库?

javascript - 在 ReactJS 中操作 Momentjs 日期

javascript - 如何使用端点返回的 JSON token 响应到 React 中的另一个 .js 文件

reactjs - 尝试导入错误 : 'TextDecoder' is not exported from '@polkadot/x-textdecoder'

reactjs - 如何强制一个 react 组件不重新渲染?

javascript - 无法在 IE 的特定行上设置断点