Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the Difference between the React Router v4 Router Types?

I have tried to learn some React basics on YouTube and from the official docs and I encountered multiple different Routers in only two videos. Sadly, the instructor did not explain anything at all and I'm even more confused than I was before.

dr: I really don't get the difference between a browser router, a 'normal' router and an index router. Thanks everyone for helping me.

like image 607
thelearner Avatar asked Aug 02 '17 01:08

thelearner


People also ask

What are react Router types?

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.

Which Router is best for react?

React Router is the most popular library for implementing routing for React apps. It was first released in May 2014 and it grew through trial and error as React's API changed from version to version. By contrast, Reach Router's version one was released in May 2018, when React has most of its pattern fixed.

What are the Router components of react v4?

There are three primary categories of components in React Router: routers, like <BrowserRouter> and <HashRouter> route matchers, like <Route> and <Switch> and navigation, like <Link> , <NavLink> , and <Redirect>

How many types of routers are there in react JS?

They are technically three different packages: React Router, React Router DOM, and React Router Native.


1 Answers

Browser Router doc

A Router that uses the HTML5 history API (pushState, replaceState and the popstate event) to keep your UI in sync with the URL.

Route doc

Its most basic responsibility is to render some UI when a location matches the route’s path.

What the heck does that stuff mean

BrowserRouter is a React Component that watches the URL and more or less passes the current path down to its children, while a Route component will render some other component based on the URL information passed to it by its parent BrowserRouter. IndexRoute is used to set a default view when rendering a specific Route Component. For more on here.

Remember, react-router is just a set of cleverly implemented vanilla react components that can be used to simulate a server-ish side route handler, which in turn makes a Single Page App appear to be multiple pages.

Hope this helps!

like image 65
canaan seaton Avatar answered Oct 07 '22 01:10

canaan seaton