index.js
function start(){
ReactDOM.render(
<Router history={hist}>
<Switch>
<Route path="/making" component={MakingPage} />
<Route path="/dashboard" render={() => <DashboardPage name={'Tom'}/>}/>
</Switch>
</Router>,
document.getElementById("root")
);
}
我可以像这样给出参数 name
。
仪表板页面.js
class DashboardPage extends React.Component {
constructor(props) {
super(props);
}
render(){
console.log(this.props.name)// Tom comes here!
}
}
我可以将参数从 index.js
传递到 DashboardPage.js
现在我在 myParam=1
中有变量 MakingPage
然后我想移动到 dashboard
页面并提供 myParam=1
参数。
有可能吗?还是坏主意?
export default function MakingPage(props) {
function giveParam(){
let mParam = 1;
//I want to move /dashboard page and give the `myParam=1` to `dashboardPage` like `name={'Tom')`
}
return (
);
}