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

redux-first-history rr6 router: Maximum update depth exceeded error in unknown route redirect #81

Closed
arnriu opened this issue Jun 8, 2022 · 2 comments

Comments

@arnriu
Copy link

arnriu commented Jun 8, 2022

Hello,

While updating to cra5, rr6, etc... I had this bug: when reaching an unknown path, if I use rr6 Navigate component to redirect, I have a Maximum update depth exceeded error.

  <Routes>
    <Route path="path1" element={<MyElement1/>} />
    <Route path="path2" element={<MyElement2/>} />
   {/* etc... */}
    <Route path="*" element={<Navigate replace to="/home" />} />
  </Routes>

This error happens with redux-first-history rr6 router:

import { HistoryRouter as Router } from 'redux-first-history/rr6'

If I replace this router with, for instance, rr6 BrowserRouter, and keep same routes, bug is gone.

To fix it for now, I did this:

const NavigateOnce = ({ to, replace }) => {
  const navigate = useNavigate()

  useEffect(() => {
    navigate(to, { replace })
  }, [])

  return null
}

and used like this:

  <Routes>
    <Route path="path1" element={<MyElement1/>} />
    <Route path="path2" element={<MyElement2/>} />
   {/* etc... */}
    <Route path="*" element={<NavigateOnce replace to="/home" />} />
  </Routes>
@salvoravida
Copy link
Owner

Hi there, it is the same of #80

lmk if all good

@salvoravida
Copy link
Owner

@arnriu fixed here #88

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

No branches or pull requests

2 participants