React-router的跳转方式

#1

react-router 1.0.0使用createHashHistory,在一些需要手动触发的情况下,目前是直接使用location.hash进行触发,这种触发方式是否有问题,是否还有其他更好的触发方式?

    import React from 'react'
    import { Link } from 'react-router'

    export default class Edit extends React.Component {
      constructor(props) {
        super(props);
        this.render = this.render.bind(this);
      }
      goToIndex() {
       //doSomeThing...
        window.location.hash = '#Index'
      }
    render() {
        return (
          <div className="page-car-edit page">
              <section className="card-item" onClick = {this.goToIndex.bind(this)}>
              </section>
          </div>
        )
      }
}
#2

难道不应该是history.pushState(null, ‘/’) or history.replaceState(null, ‘/’)

#3

使用createHashHistory的话,history.pushState(null, ‘/’)是无效的

#4
// history.js
history = createHashHistory()

// index.js
import history from './history'
ReactDOM.render(<Router history={history} routes={routes}></Router>, ...)

// your component or actions
import history from './history'
// ...
history.pushState(null, '/')
#5

3q,这样确实可以

import { createHashHistory } from 'history'
const history = createHashHistory()
ReactDOM.render(<Router history={history} routes={routes}></Router>, ...)
#6

nothx,其实doc里面都有

#7

我现在跳转遇到问题了

#8

这样不行呀,你可以看看