I'm using react-router-dom v6. I want to force my app to follow an specific route order. This is my router file:
<Routes>
<Route path="/" element={<DefaultLayout />}>
<Route index element={<Home />} />
<Route path="checkout" element={<Checkout />} />
<Route path="success" element={<Success />} />
</Route>
<Route path="*" element={<Navigate to="/" />} />
</Routes>
I want the route order to be like:
- Only access checkout page from home
- Only acess success page from checkout
I know that I can do this by using
useEffect(() => {/*check if it came from where spected, else return last page*/}, [])
inside my components with somekind of history, to see if it matches. But I want to know if there is a way of doing this in my router file.