react中js实现路由跳转

  1. 第一种方法是使用browserHistory.push
import { browserHistory } from 'react-router'

 ...
  handleSubmit(event) {
    event.preventDefault()
    const userName = event.target.elements[0].value
    const repo = event.target.elements[1].value
    const path = `/repos/${userName}/${repo}`
    browserHistory.push(path)
  },

  1. 第二种方法是使用context对象。
export default React.createClass({

  // ask for `router` from context
  contextTypes: {
    router: React.PropTypes.object
  },

  handleSubmit(event) {
    // ...
    this.context.router.push(path)
  },
})

es6写法:

import React, {
    Component
} from 'react';
export default class Supply extends Component {
    static contextTypes = {
        router: React.PropTypes.object
    };

......

let req = {
                pathname: "/supply/search_result",
                query: {
                    data: e
                },
            };
this.context.router.push(req);

跳转到的页面通过this.props.location.query对象获取传递的参数
[1] React Router 使用教程

你可能感兴趣的:(react中js实现路由跳转)