Passing props to component in React Router 4

后端 未结 6 1900
太阳男子
太阳男子 2021-02-05 06:39

I am new to react-router and I just started writing an app using react-router V4. I would like to to pass props to components rendered by and I am w

6条回答
  •  無奈伤痛
    2021-02-05 07:37

    You must use the render prop instead of component to pass on custom props, otherwise only default Route props are passed ({match, location, history}).

    I pass my props to the Router and child components like so.

    class App extends Component {
    
      render() {
        const {another} = this.props
        return 
      }
    }
    
    const Routes = (props) =>
      
         
          
        }/>
        
        
           ...
        }/>
      
    

提交回复
热议问题