What is the proper way to issue a redirect from a ReactJS / Reflux component?

59 Views Asked by At

I have an Actions class created via Reflux.createActions(), a Store class which extends Reflux.Store (ES6-style), and a Component which extends Reflux.Component.

The component is effectively just a simple <Button /> which the user can click on. When clicked, it makes a PUT request to the server. Most of the time, the response causes a state change to the Store. However, for certain responses, I need it to redirect to another page in my web application completely.

I'm very new to React so forgive my ignorance here. I assumed it would be something like this:

class MyStore extends Reflux.Store {

    // ...more code here...

    onActionCompleted(response) {
        if (response.specialCase === true) {
            this.props.history.push('/special');
        } else {
            // ...update state...
        }
    }

}

However that doesn't seem to do it. What is the proper way to go about doing arbitrary, programmatic redirects in React?

0

There are 0 best solutions below