12 react-router interesting facts

1. react does not have a router out of the box

React Nathan Krasney
2 min readDec 6, 2021

This is unlike angular, however angular is a framework while react is a UI library

2. react-router-dom is the de facto router used in react projects (here)

react-router-dom popularity

3. Major version — 6.0.0 was officially released a month ago

but most downloads use version 5.2.0 (versions)

popular react-router-dom versions

4. The creator of react-router is Michael Jackson

I am not referring here to the singer …

5. You need to install only react-router-dom, react-router is a dependency

following is enough

npm i react-router-dom

6. BrowserRouter is based on DOM window object history API

The latter is wrapped in the history module

BTW, Michael Jackson is also the creator of the history module

7. react-router holds core functionality which both react-router-dom and react-router-native uses.

This concept somewhat reminds the separation of concern done by the react team with react vs react-dom \ react-native

8. Current weekly downloads for react-router is above 6M

react-router weekly downloads

9. react-router-dom exposes 5 router components

All of these router components can be used also via the low-level Router component

This is the full list :

  • BrowserRouter,
  • HashRouter
  • MemoryRouter
  • NativeRouter
  • StaticRouter.

10. The Link component is a wrapper around <a> element.

The Link component calls preventDefault() to eliminate page refresh and eliminate state lost

11. react-router provides declarative routing

This concept is aligned with react principles (here)

12. The Router component uses context

Context is used via Router.Provider to pass props: history, location, and params to its components child consumers.

Using context eliminates props drilling

--

--

React Nathan Krasney

25+ years developing software. Lead web instructor & mentor. Focused in last few years on React. Check more info in www.nathankrasney.com