question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redirection not work after action

See original GitHub issue

Hi, I have using connected-react-router 6.1.0 in my react project stack.

react -> 16.7.0 react-router-dom -> 4.3.1 react-redux -> 6.0.0 redux-thunk -> 2.3.0

I have configurated my app, and router works perfectly (I can use the Redirect component from react-router). The problem that I have detected is produced when I am doing an API call (action) and before I want to redirect (promise finish). I don´t know why the location path change to the right URL but the page component not is loaded, (If I reload the page I can continue).

Example:

import React, { Component } from "react";
import { connect } from "react-redux";
import { bindActionCreators } from "redux";
import { push } from "connected-react-router";

import {redirectAction} from "./actions.js";

sampleComponent extends Component {
  constructor (){...}
  
  formSending = async () => {
    await this.props.firstApiCall() // like 5 seconds
    await this.props.secondApiCall() // like 500ms

   // Here I want to redirect I have try with this:

  this.props.redirect("/new-route");
  this.props.push("/new-route");
  // I have try creating an action how explain in the FAQ
  this.props.redirectWithAction("new-route");

  }
}

mapDispatchToProps = (dispatch) => ({
  redirect: bindActionCreators(push, dispatch),
  push,
  redirectWithAction: bindActionCreator(redirectAction, dispatch)
});

export default connect(null, mapDispatchToProps)(sampleComponent);
/// actions.js

export const redirectAction = route => dispatch => {
  console.log("Redirecting to", route);
  dispatch(push(route));
};

Anyone can help me, please?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:15
  • Comments:23 (4 by maintainers)

github_iconTop GitHub Comments

10reactions
jambyungcommented, Feb 7, 2019

I had a same problem. This was indeed very simple problem. I looked at the installation steps and found that I was using BrowserRouter under ConnectedRouter

Router.js

const Router = () => {
  return (
    <BrowserRouter>
      <React.Suspense fallback={Loading}>
        <Switch>
          <Route exact path={ROUTER_ROOT} component={HomePage} />
        </Switch>
      </React.Suspense>
    </BrowserRouter>
  );
};

index.js

if (root) {
  ReactDOM.render(
    <Provider store={store}>
      <ConnectedRouter history={history}>
        <Router />
      </ConnectedRouter>
    </Provider>,
    root
  );
}
6reactions
GianDigiacommented, May 27, 2020

Same here.

I also installed unnecessary peer dependencies just to be sure

"react-router": "5.1.2"
"react-router-dom": "^5.1.2"
"connected-react-router": "^6.8.0"
"react-redux": "^7.2.0"
"redux-thunk": "^2.3.0"
Read more comments on GitHub >

github_iconTop Results From Across the Web

RedirectToAction not changing URL or navigating to Index view
I just came across this issue and nothing was working for me. It turned out the controller I was redirecting to ...
Read more >
Redirect to action is not working - CodeProject
Accept Solution Reject Solution. I don't know why it was redirecting to error Page : but in sample application it was working fine....
Read more >
Asp.net core MVC Redirect to action not working - YouTube
Asp.net core MVC Redirect to action not working in area : How to fix routing issue.
Read more >
RedirectToAction does not change the view and URL
I am using following code to redirect to another view. return RedirectToAction("Project", "ControllerName"); Control goes to action and it executes the code ...
Read more >
ASP.NET Core - Redirect To Action not working - MSDN
I've been struggling with a simple issue, a simple RedirectToAction is not working for me when posting a form. Here is my code:...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found