索引.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 (
);
}