Javascript React路由器-历史记录未定义问题
我在尝试处理React路由时遇到问题。 我有一个项目正在进行。我安装了react,react dom,react路由器。我导入了以下内容:Javascript React路由器-历史记录未定义问题,javascript,reactjs,react-router,url-routing,Javascript,Reactjs,React Router,Url Routing,我在尝试处理React路由时遇到问题。 我有一个项目正在进行。我安装了react,react dom,react路由器。我导入了以下内容: import { Router, Route, IndexRoute, hashHistory } from "react-router"; 渲染方法如下所示: ReactDOM.render( <Router history={hashHistory}> <Route path="/" component={Ap
import { Router, Route, IndexRoute, hashHistory } from "react-router";
渲染方法如下所示:
ReactDOM.render(
<Router history={hashHistory}>
<Route path="/" component={App}>
<IndexRoute component={Featured}></IndexRoute>
<Route path="archives" component={Archives}></Route>
<Route path="settings" component={Settings}></Route>
</Route>
</Router>,
app
);
app Component没有历史道具,应该绑定到此道具,但道具不存在。这就是我要问的:)不,它不会绑定到这个,路由器组件有作为道具的历史记录,而不是应用程序组件Nevermind,问题在于路由器和历史记录的版本。应用程序组件没有历史道具它应该绑定到这个,但道具不存在。这就是我要问的:)不,它不会与此绑定,路由器组件作为道具具有历史记录,而不是应用组件Nevermind,问题在于路由器版本和历史记录。
import React from 'react';
import { Link } from 'react-router';
export default class App extends React.Component {
navigate() {
console.log(this.props);
this.props.history.pushState(null, '/');
}
render() {
return (
<div>
{this.props.children}
<Link to="archives"><button>archives</button></Link>
<Link to="settings"><button>settings</button></Link>
<button onClick={this.navigate.bind(this)}>featured</button>
</div>
)
}
}
{
"name": "react",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "webpack-dev-server --content-base --inline --hot",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.18.2",
"babel-loader": "^6.2.7",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-react-html-attrs": "^2.0.0",
"babel-plugin-transform-class-properties": "^6.18.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2015": "^6.18.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
"history": "^1.17.0",
"react": "^15.3.2",
"react-dom": "^15.3.2",
"react-router": "^3.0.0",
"webpack": "^1.13.3",
"webpack-dev-server": "^1.16.2"
}
}