Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the different between Router vs Route in react-router-dom

In the React-Router documentation I have seen that It has import both Route and Router modules from react-router-dom. I would like to know what is the different between those two modules?

like image 826
TMKasun Avatar asked May 13 '17 05:05

TMKasun


People also ask

What is the difference between react router Dom and react router?

The primary difference between them lies in their usage. React Router DOM is for web applications and React Router Native is for mobile applications made with React Native.

What is routes in react router Dom?

Route: Route is the conditionally shown component that renders some UI when its path matches the current URL. Link: Link component is used to create links to different routes and implement navigation around the application. It works like HTML anchor tag.

What is the difference between router and route?

In a WAN, routers serve as connection points between sub-networks, more generally referred to as nodes. Routing between sub-networks is guided by a routing table maintained in each end-system. The routing table points to the next device along a route for a packet to take in order to reach a given address.

How many routers does Dom react router have?

On the basis of the part of URL that the router will use to track the content that the user is trying to view, React Router provides three different kinds of routers: Memory Router. Browser Router. Hash Router.


1 Answers

Router

Router component is what makes the connection between browser location and the react application. It doesn't render anything visible on your page. It just exposes API to interact with location changes of the browser via React context. So any component down the tree can use this API to change their behavior based on location changes in the browser or change the browser location into what they want.

Router is the abstract for all other specific router components. Practically, we use a specific implementation of it like BrowserRouter, MemoryRouter, and HashRouter which use different methods to manage browser history. Also, Router is usually a top-level component in the component tree and use only one time in the entire application. All other react-router components should be descendants of Router as they can't function without the API which Router provides.

Route

Route is much simple to explain. It just renders some UI when a location matches the route’s path. So an application can have many Routes based on its layout complexity in different levels of the component tree. Also, Route has some additional props to configure how the match should happen. Route internally use API provided by Router to access the location and decide whether to render the given component or not.

like image 83
Tharaka Wijebandara Avatar answered Oct 20 '22 22:10

Tharaka Wijebandara