Skip to content

How to navigate outside of components in ReactRouter 4? #5237

@RamYadlapalli

Description

@RamYadlapalli

In React Router (v3) I can accept a server response and use browserHistory.push to go to the appropriate response page. However, this isn't available in v4, and I'm not sure what the appropriate way to handle this is in React-Router V4 .

In below example when the server returns a success, the user is taken to the Cart page

// actions/index.js
export function addProduct(props) {
  return dispatch =>
    axios.post(`${ROOT_URL}/cart`, props, config)
      .then(response => {
        browserHistory.push('/cart'); // no longer in React Router V4
      });
}

How can I make a redirect to the page from function in React Router v4?

I can find lot of references on navigation from components in my case i need to navigate from a function

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions