I am in /customerOrders/13 page and from there I try to redirect to /customerOrders/14 using navigate('/customerOrders/14'). Even though the URL is updated, page is not redirected to /customerOrders/14.
Below are code fragments I extracted related to this from the codebase.
App.js
import {
BrowserRouter,
Routes,
Route
} from "react-router-dom";
...
<BrowserRouter>
<Routes>
<Route path="customerOrders/:id" element={<CustomerOrderForm />}></Route>
</Routes>
<Router>
CustomerOrderForm.jsx
import { useNavigate } from "react-router-dom";
...
const CustomerOrderForm = () => {
let navigate = useNavigate();
const save = async () => {
//
// logic to persist data goes here...
//
navigate(`/customerOrders/${customerOrderId}`);
}
...
}
customerOrder/14. If you are using useEffect in that component, add the id param from route as a dependency to useEffect.import { useNavigate } from 'react-router-dom';const history = useNavigate();` thenhistory('...');useNavigate() may be used only in the context of a <Router> component.import { useParams } from "react-router-dom";and thenlet id = useParams().id;. Id is fetched already... but the problem is I cannot redirect from this page to another.historyas well. I read this SO question and still no luck.