首先在packjson加homePage
"name": "login",
"version": "0.2.0",
"private": true,
"homepage": "login",
注意要添加basename,打包后就不会出现跳去根路径的问题了
import {
BrowserRouter as Router,
Switch,
Route,
Redirect,
} from "react-router-dom";
import Home from '../pages/home/home'
import Register from '../pages/register/register'
<Router basename="/login">
<Switch >
<Route exact path="/">
<Redirect to="/home"></Redirect>
</Route>
<Route component={Home} path="/login" exact={true}>
</Route>
<Route component={Register} path="/register" exact={true}>
</Route>
</Switch>
</Router>