Redirection not work after action
See original GitHub issueHi, 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:
- Created 5 years ago
- Reactions:15
- Comments:23 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
index.js
Same here.
I also installed unnecessary peer dependencies just to be sure