Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of React Router?

Given that we can do routing with Express on the server, why do need a client side router? What are the benefits, and is it only significant to SPA?

like image 947
user235692 Avatar asked Jul 18 '16 06:07

user235692


1 Answers

Client side routing is required to keep your application in sync with the browser URL.

It is mainly useful for Single Page Applications where the backend will be used for RESTful API calls via XHR or AJAX calls.

Being a SPA uses can book mark your URL and when they hit the URL again , your application should load that page with the data and its state.

The main difference between Server side routing and client side routing:
1. In Server Side routing you download(serve) the entire page.
2. In client Side routing along with the entire page, you can serve a specific portion of a page, reuse the DOM, manually manage the URL and history states. eg.

www.something.com/page1/tab1 will show tab1 in the UI
www.something.com/page1.tab2 will show tab2 in the UI

In this way the url can get more complex and you can have sub-routes with states.

like image 122
Sanyam Agrawal Avatar answered Oct 19 '22 00:10

Sanyam Agrawal