Method 1:
import {Switch, Route, Router, HashHistory, Link} from 'react-router-dom';
Copy the code
Write 2
import {Switch, Route, Router} from 'react-router';
import {HashHistory, Link} from 'react-router-dom';
Copy the code
Respective functions
-
React-router: Implements core routing functions
-
React-router-dom: react-router-dom: react-router-dom: react-router-dom: react-router-dom: react-router-dom The Link component, which renders the A tag, BrowerRouter, and HashRouter components, which use pushState and popState events to build routes, and Window. hash and hashchange events to build routes. It already relies on the React-Router library
-
React-router-native: React-router is based on the react-router, similar to the react-router-DOM, adding some functions of the react-native runtime environment.
Using the difference between
- Browser-based development: React -router-dom
- React-router-native: react-router-native