Well, indeed there is difference between them. When you are using react-router you use Router and Link components to render the about component which will send you the about page link.
<Link to='/about'>About</Link>
< Route path="/about" component={About} />
it's kinda same in express, if you render a view like this :
app.get('/about', function (req, res) {
res.render('about.html')
})
Let's see, you want your database data on the front-end. If you use normal view engines like ejs,
handlebars then after finding the data from db you will render them to html or ejs page.
If you are using react for single page application then you don't need react-router. But if your app has multiple pages, then using react-router is good.
See this below example code:
app.get('/about', function(req, res) {
// finding the user details from database
user.find()(function(err, users) {
if (err) {
console.log(err);
} else {
res.json(users); //sends the user data
}
});
And now, React have to grab this data from the backend, It can be done by many approaches, I prefer to use axios package which is a npm does the same job as FETCH API does.
axios.get('http://localhost:5000/about')
.then(response => {
this.setState({users: response.data}); //this reponse.data is coming from backend
})
.catch(function (error) {
console.log(error);
})
So now, you see react-router-dom is not the same as express routing.
< Route path="/about" component={About} />
, you can give this address
anything you like i.e "/details"
etc. You only have to give axios.get(endpoint)
address as the same as express endpoint. But you must have to use Link
from react-router-dom to going to the exact endpoint path of express routing.
<Link to='/about'>About</Link>
should be same as app.get('/about',.....)
Hopefully, this will resolve your issues about understanding react-router and express routing.