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

[Bug]: navigate not working (not doing anything) when used inside useEffect #12140

Closed
XHCui opened this issue Oct 17, 2024 · 2 comments
Closed
Labels

Comments

@XHCui
Copy link

XHCui commented Oct 17, 2024

What version of React Router are you using?

v6.19.0

React version: v18.2.0

Steps to Reproduce

The user will access the page with url like '..../place/claim?...'

and the page have following code:

useEffect(() => {
    const getProfile = async () => {
       // api call getting stuff
       
       navigate('/place', { replace: true })
    }
    
    getProfile()
}, [...])

However, the navigate never works here

tried following as well:

const [shouldNavigate, setShouldNavigate] = useState(false);

useEffect(() => {
    const getProfile = async () => {
       // api call getting stuff
       
       setShouldNavigate(true);
    }
    
    getProfile()
}, [...])

if (shouldNavigate) {
  return (<Navigate to='/place' replace={true} />)
}

also doesn't redirect

Expected Behavior

url redirect to the /place

Actual Behavior

Nothing happens

@XHCui XHCui added the bug label Oct 17, 2024
@XHCui XHCui closed this as completed Oct 18, 2024
@nanianlisao
Copy link

Same bug, how to fix it? @XHCui

@nanianlisao
Copy link

@brophdawg11 Can you help me? This problem occurs in data router. I checked a lot of PR related to this, such as #8929, but this problem still exists.

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

2 participants