react路由后退.go()

82 阅读1分钟

1.引入相应的包

import { createBrowserHistory } from 'history';

安装history

npm i history

//创建history,可以用于路由 传参,路由前进后退

  const history = createBrowserHistory()

//返回上一个历史导航

history.go(-1);

history.back();

// 去往下一个路由

history.go(1);

history.forward();

//路由传参

history.push({pathname:'/home',search:'?the=query'},{

some:state

})

history.push({})