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.
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.
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.
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>
They are technically three different packages: React Router, React Router DOM, and React Router Native.
A
Router
that uses the HTML5 history API (pushState, replaceState and the popstate event) to keep your UI in sync with the URL.
Its most basic responsibility is to render some UI when a location matches the route’s path.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With