0

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")
  );
}

I can give the param name like this.

DashboardPage.js

class DashboardPage extends React.Component {
  constructor(props) {
    super(props);
  }
  render(){
    console.log(this.props.name)// Tom comes here!
  } 
}

I could pass the param from index.js to DashboardPage.js

Now I have the variable myParam=1 in MakingPage

then I want to move to dashboard page and give the myParam=1 parameter.

Is it possible? or bad idea?

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 (

  );
}
whitebear
  • 11,200
  • 24
  • 114
  • 237

0 Answers0