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 (
{this.props.children}
)
}
}
render((
), document.getElementById('app'));
history 使用 browserHistory 就会有警告不能显示能容,使用 hashHistory 就正常,能显示内容
警告内容如下 :
browser.js:49Warning: [react-router] Location "/rjs/index.html#/" did not match any routes.
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
因为hashHistory是根据url的hash部分(#)来改变,所以一般都会有个#,而browserHistory是通过调用浏览器history api来实现的,所以不用#。
推荐一下阮一峰的react-router教程:react-router入门
因为使用 hashHistory 改变的是 url 的哈希值,就是 # 号后面的内容,请求的文件是一样的。使用 browserHistory 改变了路径,请求的文件是不一样,所以 browserHistory 要通过服务器端设置来实现。