鍍金池/ 問(wèn)答/HTML5  HTML/ react點(diǎn)擊按鈕跳轉(zhuǎn)頁(yè)面

react點(diǎn)擊按鈕跳轉(zhuǎn)頁(yè)面

剛剛接觸react,之前的項(xiàng)目用的vue框架 ,想學(xué)習(xí)下react框架 ,這個(gè)項(xiàng)目就用react寫(xiě)了 ,現(xiàn)在遇到頁(yè)面跳轉(zhuǎn)的問(wèn)題

import { routerRedux, Route, Switch } from 'dva/router';

<div className={styles.buttonList}>
  <Button icon="plus" size="large">
    <Route path="/pages/Create/AddPlane" component='./create/add_plane'>添加機(jī)票 </Route>
  </Button>
  <Button type="primary" size="large">
    <Route path="/pages/Create/HotelList" component='./create/hotel_list'>下一步</Route>
  </Button>
</div>

這樣不行。。。

在按鈕里面寫(xiě)個(gè)方法 在方法里面寫(xiě)跳轉(zhuǎn)路由的話怎么寫(xiě)呢???

<div className={styles.buttonList}>
  <Button icon="plus" size="large" onClick={addPlane}>
    添加機(jī)票
  </Button>
  <Button type="primary" size="large" onClick={nextStep}>
    下一步
  </Button>
</div>
function addPlane() {
  console.log('添加機(jī)票');
}

function nextStep() {
  console.log('下一步');
}
回答
編輯回答
念初

你還要在路由里配置下路徑1和2要調(diào)轉(zhuǎn)的頁(yè)面。
例如:

<Link to="/aboutUs">
    關(guān)于我們
    <span> </span>
</Link>

就要在main.js里配置下路由

import React from 'react'
import ReactDOM, {render} from 'react-dom'
import 'antd/dist/antd.css'
import { Router, Route, hashHistory, browserHistory, Redirect } from 'react-router'
**import AboutUs from '../components/JCWebsite/aboutUs'**

render(<Router history={hashHistory}>
        **<Route path="aboutUs" component={AboutUs} />**
    </Router>, document.getElementById('root')
)

配置里的入口文件,比如我的:
圖片描述

2017年2月5日 20:45
編輯回答
夏夕

剛好今天有寫(xiě)到點(diǎn)擊按鈕跳轉(zhuǎn)的
只要更改location下的pathname就可以了
如圖

圖片描述

圖片描述

2017年2月8日 03:44