user8813240
user8813240

Reputation: 125

React router Dom and express

I am a meteor user and I want to know the difference between express and react router Dom. When I used meteor, I would render a component that contained the browser router and routes. But I am kind of confused why people are using express with react when they can use react router Dom. Is it a preference thing or is there benefits to one that the other does not have? Or am I just wrong and they are two separate things? Please explain the difference of the two and how they would be used differently.

Upvotes: 0

Views: 1719

Answers (1)

anand
anand

Reputation: 575

Express

  • Express works on the server-side. Specifically, it runs on top of node.js
  • Express is a 'web application framework', and can handle routes, accept client requests, retrieve data from databases, prepare views and send back responses.
  • Note once again that all of that is on the server side.

React-router-dom

  • React-router-dom is a client side routing library.
  • You might be aware that in Single Page Applications, when a user navigates to a link, a request to the server is typically not sent. Instead, the client side router (like react-router-dom) interprets the request and show appropriate content (eg: a specific react component).

To answer your question why people use express with react could be

  • to serve your index.html and your bundle.js files, when a user first visits the site, (www.example.com)
  • to redirect the user to www.example.com when someone directly visits www.example.com/subpage, which is typically handled by react-router-dom on the client,
  • to serve static assets like icons and images on your page
  • as an API backend for getting data from the server, etc

Upvotes: 3

Related Questions