How can react-route pass parameters to components without redux?


class Home extends Component {

    constructor(props) {
        super(props)
    }

    doSomething() {
        
    }

    render() {
        return (
            <div>
                <Child onDoSomething={this.doSomething} />
            </div>
        );
    }
}

HomedoSomethingChildreduxredux
class Home extends Component {

    constructor(props) {
        super(props)
    }

    doSomething() {

    }

    render() {
        return (
            <div>
                <Route path="/child" component={Child} />
            </div>
        );
    }
}

Mar.10,2021

you can load subcomponents as render on Route , so you can pass your functions and so on.


class Home extends Component {

    constructor(props) {
        super(props)
    }

    doSomething() {

    }

    render() {
        return (
            <div>
                <Auth path='/user' component={User} onDoSomething={this.doSomething} />
            </div>
        );
    }
}



class Auth extends Component {

    constructor(props) {
        super(props)

    }

    render() {

        let { component: Part, ...rest } = this.props

        
        return (
            <div>
                <Route {...rest} render={(props) => {
                    // restonDoSomethingUser<Part {...rest} {...props} />
                    return (
                        true ? <Part {...rest} {...props} /> : <Redirect to={{pathname: '/login', state: {from: props.location }}} />
                    )

                }} />
            </div>
        );
    }
}


Menu