import React,{Component} from 'react';
import {render} from 'react-dom';
import { Router, Route, Link, browserHistory, IndexRoute, hashHistory} from 'react-router'
class App extends Component {
constructor () {
super();
this.state = {};
}
render() {
return (
<div>
{this.props.children}
</div>
)
}
}
render((
<Router history={browserHistory}>
<Route path="/" component={App}>
<IndexRoute component={Test} />
</Route>
</Router>
), document.getElementById('app'));
history
使用 browserHistory
就会有警告不能显示能容,使用 hashHistory
就正常,能显示内容
警告内容如下 :
browser.js:49Warning: [react-router] Location "/rjs/index.html#/" did not match any routes.
因为hashHistory是根据url的hash部分(#)来改变,所以一般都会有个#,而browserHistory是通过调用浏览器history api来实现的,所以不用#。
推荐一下阮一峰的react-router教程:react-router入门