connected-react-router icon indicating copy to clipboard operation
connected-react-router copied to clipboard

Why 'yield(push('/xxx'))' can't jump to the next page?Must I refresh the browser?

Open amazingzcj opened this issue 5 years ago • 13 comments

export function* loginFetch(action) {
    try {
        const info = yield call(loginUserFetch, action.params);
        console.log(info)
        if(!info) return yield put({type: actionTypes.LOG_FETCH_FAIL, loading:false });
        if (Object.keys(info).length > 0) {
            const {id, name, token} = info;
            manageSession.judgeSession("userId", id);
            manageSession.judgeSession("userName", name);
            manageSession.judgeSession("token", token);
            yield put({type: actionTypes.LOG_FETCH_SUCCESS, info});
            yield put(push("/main"));
        }
    } catch (error) {
        yield put({type: actionTypes.LOG_FETCH_ERROR, isLogin: false})
    }
}

actually it works,the URL has changed,but the page doesn't

amazingzcj avatar May 05 '19 08:05 amazingzcj

@amazingzcj did you ever figure this out? I'm facing the same issue right now.

Both on latest versions of this lib, react-router and react-router-dom as well as on v6.0.0 and v4.3.1 respectively.

favna avatar May 26 '19 23:05 favna

@Favna not yet, because of no error or warning infos. my react-router and react-router-dom are both v5.0.0. try update the version, and try use withRouter outside your component, and see push whether works, if not ,then, you maybe have to refresh the browser.

amazingzcj avatar May 27 '19 03:05 amazingzcj

I'm not sure what exactly it was but I managed to.. solve... It? I use this lib v6.4.0, react-router and react-router-dom v5 and v6 of react-redux.

Turns out the problem I was facing was actually something completely different not related to routing but since I had routing issues in the past that's where I assumed it was now.

If you want I can share how exactly I set up my redux-saga - store - router link.

favna avatar May 27 '19 16:05 favna

I'm not sure what exactly it was but I managed to.. solve... It? I use this lib v6.4.0, react-router and react-router-dom v5 and v6 of react-redux.

Turns out the problem I was facing was actually something completely different not related to routing but since I had routing issues in the past that's where I assumed it was now.

If you want I can share how exactly I set up my redux-saga - store - router link.

sure, I want. Thanks for sharing with me. It really confuses me.

amazingzcj avatar May 28 '19 04:05 amazingzcj

@amazingzcj I've posted it on Gist here: https://gist.github.com/Favna/f4e7bf31cd8240d9d0fb9f2501b7e47c

See the comment after all the files for a table of contents of sorts.

favna avatar May 29 '19 20:05 favna

I have this issue but I think its perhaps a bug in react-router?

I have two apps that merged together and I listen for hash navigations from the old app and then push a redux push navigation action to redirect to the new location.

Seems if I listen for a @@router/LOCATION_CHANGE action then dispatch a replace then the url updates but the page doesn't update. You can see in the react debugger that state of react-router is the first location change and it doesn't get the state from the replace (its visible in the redux debugger).

Seems if you put a 1ms timeout and dispatch the replace later it works :/

AndyBan avatar May 31 '19 10:05 AndyBan

having the same problem in redux-thunk. push() method changes the url but does not change the view. It doesn't even dispatch any action.

hisham-blackbuck avatar Jul 08 '19 07:07 hisham-blackbuck

having the same problem in redux-thunk. push() method changes the url but does not change the view. It doesn't even dispatch any action.

sorry...maybe you need use the withRouter to wrap your component

amazingzcj avatar Jul 17 '19 12:07 amazingzcj

I have this issue but I think its perhaps a bug in react-router?

I have two apps that merged together and I listen for hash navigations from the old app and then push a redux push navigation action to redirect to the new location.

Seems if I listen for a @@router/LOCATION_CHANGE action then dispatch a replace then the url updates but the page doesn't update. You can see in the react debugger that state of react-router is the first location change and it doesn't get the state from the replace (its visible in the redux debugger).

Seems if you put a 1ms timeout and dispatch the replace later it works :/

actually i cant find what happened...now i let the page refresh instead then it worked

amazingzcj avatar Jul 17 '19 12:07 amazingzcj

@amazingzcj Any update of this? I have the same issue. When I dispatch the push the URL change but the component doesn't change.

ctkc avatar Aug 29 '19 15:08 ctkc

Same issue and it's annoying. The problem is still happen "connected-react-router": "^6.6.1" / "react-router-dom": "5.1.2".

maxrikotero avatar Jan 27 '20 14:01 maxrikotero

I have the same issue. Is there any solution?

songjoe avatar Jun 15 '20 08:06 songjoe

I have the same issue. I changed URL when user is unathorized:

export default function* root() {
  yield takeEvery(LOCATION_CHANGE, routerSaga);
}

function* routerSaga({ payload }: LocationChangeAction) {
  const path = payload.location.pathname as Routes;

  switch (path) {
    case RouteNames.page1: {
      yield call(page1Saga);
    }
  }
}

function* page1Saga() {
  yield put(push(RouteNames.signIn)); // when user unauthorized
}

Temporary solution: https://github.com/supasate/connected-react-router/issues/337#issuecomment-586019315

function* page1Saga() {
  yield delay(1); // Add delay
  yield put(push(RouteNames.signIn)); // when user unauthorized
}

Example: https://codesandbox.io/s/connected-react-routerissue-304-v2gll?file=/src/sagas/index.ts

flibustier7seas avatar Nov 02 '20 11:11 flibustier7seas