1.组件中使用withRouter
import { withRouter } from "react-router-dom";
function Siderbar(props) {
console.log(props);
return (
......
)
}
export default withRouter(Siderbar)
2.使用history插件
npm install --save history
import { createHashHistory } from 'history'; // hash路由
import { createBrowserHistory } from 'history'; // history路由
const history = createHashHistory()
history.push("/login")