Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Redirect from redux-store #8488

Closed
Kamran95 opened this issue Dec 15, 2021 · 4 comments
Closed

[Feature]: Redirect from redux-store #8488

Kamran95 opened this issue Dec 15, 2021 · 4 comments
Labels

Comments

@Kamran95
Copy link

What is the new or updated feature that you are suggesting?

before you could redirect from redux actions using history.push() method but it doesn't seem to be possible as useNavigate can only be used in react functional component

Why should this feature be included?

there should be a method to redirect user from redux store as it used to be done by history.push(). now if we use history.push() it changes route but component remains the same as route change is not detected.

@umermughal1

This comment has been minimized.

@filzahamjad

This comment has been minimized.

@timdorr
Copy link
Member

timdorr commented Dec 15, 2021

Please search before posting a new issue. This has already been answered: #8481 (comment)

@timdorr timdorr closed this as completed Dec 15, 2021
@Kamran95
Copy link
Author

Kamran95 commented Dec 17, 2021

Your proposed solution doesn't work in redux store as route changes but components doesn't re render
the page remains same

APP.js

import "./App.css";
import Routes from "./Routes/router";

import {
unstable_HistoryRouter as HistoryRouter,
BrowserRouter,
} from "react-router-dom";
import { createBrowserHistory } from "history";

let history = createBrowserHistory();

function App() {
return (
<HistoryRouter history={history}> <Routes /> </HistoryRouter>
);
}

export default App;

Redux Store actions
import { createBrowserHistory } from "history";
let history = createBrowserHistory();

export const Login = (data) => (dispatch) => {
console.log("Welocme to login Action");
public_url
.post("auth", data)
.then((res) => {
let data = {
userDetails: res.data.data,
token: res.headers["x-auth-token"],
};
dispatch(LoginSuccess(data));
history.push("welcome");

})
.catch((err) => {
  if (err.response) {
    const errors = err.response.data.errors;
    dispatch(LoginFailed(errors));
  }
});

};

Issue

route changes to localhost:3000/welcome but page remains same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants