import { Switch, Route, Router } from 'react-router';

import { Swtich, Route, BrowserRouter, HashHistory, Link } from 'react-router-dom';
Copy the code

1. API

The React – the router:

Provides a core API for routing. Such as Router, Route, Switch, etc., but there is no API for dom operation for Route jump;

The React – the router – the dom:

BrowserRouter, Route, Link and other apis can be provided to trigger events to control routes through DOM manipulation.

Link component, which renders an A tag; The BrowserRouter and HashRouter components, the former using pushState and popState events to build routes, and the latter using hash and HashChange events to build routes.

2. Dynamic route redirection

The React – the router:

This.props.history. Push (‘/path’);

This.props. Router. Push (‘/path’);

The React – the router – the dom:

This.props.history. Push (‘/path’)

3. Use differences

React-router-dom extends the REact-router API for manipulating dom.

Swtich and Route both import and re-export components from the React-Router without any special processing.

The package.json dependency in the react-router-dom has a dependency on the react-router. Therefore, NPM does not need to install the React-router.

  • Install react-router-dom directly from NPM and use its API.