我有以下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/