反应路由器:警告:失败的上下文类型:未指定所需的上下文“路由器”
react-router: Warning: Failed Context Types: Required context `router` was not specified
我克隆了最新的 react-router
存储库:
一切正常,
然后我将 auth-flow
示例复制到我自己的文件夹中以 运行 测试演示
但出现此错误:
webpack.config.js
module.exports = {
entry: './app.js',
output: {
path: __dirname + '/build/',
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['react', 'es2015']
}
}
]
}
};
package.json
{
"name": "reacttest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.3.26",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"history": "^1.17.0",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-router": "^1.0.3",
"webpack": "^1.12.9"
}
}
我错过了什么,
如何修复此错误?
在您的 Login
组件中,您尝试访问 this.context.router
但您未能指定 Login
应该有权访问它。
class Login extends React.Component {
static contextTypes = {
router: React.PropTypes.func.isRequired
}
render() {}
}
应该改用 History mixin。
查看最新分支以查看正确的示例代码
我克隆了最新的 react-router
存储库:
一切正常,
然后我将 auth-flow
示例复制到我自己的文件夹中以 运行 测试演示
但出现此错误:
webpack.config.js
module.exports = {
entry: './app.js',
output: {
path: __dirname + '/build/',
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['react', 'es2015']
}
}
]
}
};
package.json
{
"name": "reacttest",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"babel-core": "^6.3.26",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"history": "^1.17.0",
"react": "^0.14.3",
"react-dom": "^0.14.3",
"react-router": "^1.0.3",
"webpack": "^1.12.9"
}
}
我错过了什么, 如何修复此错误?
在您的 Login
组件中,您尝试访问 this.context.router
但您未能指定 Login
应该有权访问它。
class Login extends React.Component {
static contextTypes = {
router: React.PropTypes.func.isRequired
}
render() {}
}
应该改用 History mixin。
查看最新分支以查看正确的示例代码