如何函数实现react-router的路由跳转

#1

文当上的路由跳转是点击标签实现的,那怎么用函数的方式就行路由跳转呢?

查了个方法import createHistory from 'history/createBrowserHistory'
然后用history.push(’/About’)就行路由跳转,但是地址栏的路径虽然变化了呢,对应的路由模块却没有发生变化

#2

你可以使用

import { withRouter } from 'react-router-dom'  

@withRouter  
class App extends React.Component{
  linkTo(){
    this.props.history.push('/xxxx')
  }
}
#3

请问一下@的用法是把改对象的属性合并到该类中吗?

#4

這個是裝飾器,你可以去了解一下js的Decorators

#5

import {hashHistory} from 'react-router';

const App = () => (
    <div>
      <input type="button" value="test" onClick={() => {hashHistory.push('/user/reg')}} />
    </div>
)
#6

先说明好版本,v3和v4的api差别挺大的。