//页面路由1
2window.location.href='url';
history.back();
//hash路由1
2
3
4window.location='#hash'
window.onhashchange=function(){
console.log(window.location.hash);
}
//H5路由1
2
3
4
5
6
7
8
9
10
11//推进一个状态
history.pushState('name','title','/path');
//替换一个状态
history.replaceState('name','title','/path');
//popstate
window.onpopstate=function (ev) {
console.log(window.location.href)
console.log(window.location.pathname)
console.log(window.location.hash)
console.log(window.location.search)
}
React-Router
<BrowserRouter>/<HashRouter>
,路由方式
<Route>
,路由规则
<Switch>
,路由选项
<Link>
/<NavLink>
,跳转导航
<Redirect>
,自动跳转
1 | //哈希路由地址显示localhost:8000#/a |