react-router-dom直接结构hashHistory没办法使用

react-router-dom(react-router4)中有一个 BrowserRouter 或是 HashRouter 任选其一就可以直接使用。下边是官方给的一个案例,可以参考一下

	import React from "react";
	import {
	 BrowserRouter as Router,
	 Switch,
	 Route,
	 Link,
	 useRouteMatch
	} from "react-router-dom";
	
	// This example show how you could create a custom
	//  that renders something special when the URL
	// is the same as the one the  points to.
	
	export default function CustomLinkExample() {
	 return (
	   <Router>
	     <div>
	       <OldSchoolMenuLink
	         activeOnlyWhenExact={true}
	         to="/"
	         label="Home"
	       />
	       <OldSchoolMenuLink to="/about" label="About" />
	
	       <hr />
	
	       <Switch>
	         <Route exact path="/">
	           <Home />
	         </Route>
	         <Route path="/about">
	           <About />
	         </Route>
	       </Switch>
	     </div>
	   </Router>
	 );
	}

注意使用history的是router标签
react-router-dom官方地址

你可能感兴趣的:(react-router-dom直接结构hashHistory没办法使用)