import {HashRouter} from 'react-router-dom';
import {CacheSwitch, CacheRoute} from 'react-cache-router'; //所需包
class SymptomRouter extends React.Component
{
render()
{
return <HashRouter>
<CacheSwitch>
<CacheRoute path={ '/' } exact={ true } component={ AllSymptom } />
<CacheRoute path={ '/particulars' } exact={ true } component={ Symptom }/>
</CacheSwitch>
</HashRouter>
}
}
export default SymptomRouter;
import { Link } from 'react-router-dom';
//replace是因为警告 Warning: Hash history cannot PUSH the same path; a new entry will not be added to the history stack
const path = { pathname: '/particulars', state: {};
<Link to={ path } onClick={ ()=> this.props.history.push(path) } replace>
<div style={ { color: 'blue', fontSize: '1.1rem' } } dangerouslySetInnerHTML={ { __html: drug.showName } }></div>
</Link>
所跳转的组件
console.log(this.props.location.state);