When I navigate between pages using the navbar and the buttons, the URL on the browser changes normally. But once I try to modify the URL manually, it does not work !
Example 1
- Step 1 : I open localhost:3000
- Step 2 : I click on Athletes to go to localhost:3000/Athletes
- Step 3 : I choose an athlete to go to localhost:3000/Athletes/2/AthleteSessions/
- Step 4 : I change the URL manually to localhost:3000/Athletes then I choose an athlete, I'm redirected to localhost:3000/Athletes/2/AthleteSessions/ fine until now, but when I modify the URL to put localhost:3000/Athletes/ with a slash then I choose an athlete it does not work and I'm redirected to localhost:3000/Athletes/Athletes/2/AthleteSessions/
Example 2
- Step 1, 2 and 3 are the same as the first example.
- Step 4 : I choose an AthleteSession to go to localhost:3000/Athletes/2/AthleteSessions/1/TrainingSession/ it works fine, but when I try to go back to previous page by modifying manually the URL localhost:3000/Athletes/2/AthleteSessions then I choose an AthleteSession again, it does not work and I'm redirected to localhost:3000/Athletes/2/1/TrainingSession/
App.js
import { Route, Switch, Redirect } from "react-router-dom";
<Route path="/Athletes" exact component={Athletes} />
<Route path="/Athletes/:id/AthleteSessions" exact component={AthleteSessions} />
<Route path="/Athletes/:athleteId/AthleteSessions/:athleteSessionId/TrainingSession"
exact component={AthleteTrainingSession} />
Index.js
import { BrowserRouter as Router } from "react-router-dom";
render( <Router> <App /> </Router>, document.getElementById("root") );
Athletes.js
onClick={() => {
this.props.history.push({
pathname:
"Athletes/" + ath.AthleteId + "/AthleteSessions/",
});
}}
AthleteSessions.js
passedAthleteId = this.props.match.params.id;
onClick={() => {
this.props.history.push({
pathname:
athSess.AthleteSessionId + "/TrainingSession/",
});
}}