Javascript 即使不使用路由器错误,也要对其作出反应
我在react router dom方面遇到了一些问题,特别是:Javascript 即使不使用路由器错误,也要对其作出反应,javascript,reactjs,react-router,react-router-dom,Javascript,Reactjs,React Router,React Router Dom,我在react router dom方面遇到了一些问题,特别是: warning.js?8a56:36 Warning: Failed prop type: The prop `history` is marked as required in `Router`, but its value is `undefined`. in Router printWarning @ warning.js?8a56:36 warning @ warning.js?8a56:60 checkReact
warning.js?8a56:36 Warning: Failed prop type: The prop `history` is marked as required in `Router`, but its value is `undefined`.
in Router
printWarning @ warning.js?8a56:36
warning @ warning.js?8a56:60
checkReactTypeSpec @ checkReactTypeSpec.js?d08c:80
validatePropTypes @ ReactElementValidator.js?a599:161
createElement @ ReactElementValidator.js?a599:213
(anonymous) @ app.jsx?0ec4:14
(anonymous) @ bundle.js:1289
__webpack_require__ @ bundle.js:20
(anonymous) @ bundle.js:66
(anonymous) @ bundle.js:69
Router.js?a4aa:31 Uncaught TypeError: Cannot read property 'location' of undefined
at new Router (eval at <anonymous> (bundle.js:794), <anonymous>:39:52)
at eval (eval at <anonymous> (bundle.js:2335), <anonymous>:295:18)
at measureLifeCyclePerf (eval at <anonymous> (bundle.js:2335), <anonymous>:75:12)
at ReactCompositeComponentWrapper._constructComponentWithoutOwner (eval at <anonymous> (bundle.js:2335), <anonymous>:294:16)
at ReactCompositeComponentWrapper._constructComponent (eval at <anonymous> (bundle.js:2335), <anonymous>:280:21)
at ReactCompositeComponentWrapper.mountComponent (eval at <anonymous> (bundle.js:2335), <anonymous>:188:21)
at Object.mountComponent (eval at <anonymous> (bundle.js:387), <anonymous>:46:35)
at ReactCompositeComponentWrapper.performInitialMount (eval at <anonymous> (bundle.js:2335), <anonymous>:371:34)
at ReactCompositeComponentWrapper.mountComponent (eval at <anonymous> (bundle.js:2335), <anonymous>:258:21)
at Object.mountComponent (eval at <anonymous> (bundle.js:387), <anonymous>:46:35)
我建议你:
package.json
文件中的react router dom
npm uninstall--保存react router dom
在其他情况下删除node_模块
目录,再次安装软件包,然后检查buildnpm install -g browserify
browserify ./client/src/app.js -o ./client/dist/bundle.js -t [ babelify --presets [ es2015 react ] ] -v
我已经试过你所有的建议了。我现在就去browserify查看是否有任何变化,但显然我也需要一个babelify模块。好的,在这种情况下,您需要安装
babel-preset-es2015
,babel-preset react
和babelify
到您的开发依赖项。完成。我也试过你的方法。我也遇到了同样的错误。这很奇怪,因为从堆栈跟踪来看,路由器
似乎是在某个地方声明的。您是否在代码中有这样的内容:this.props.history
?显然,出于某种原因,只在bundle.js
文件中有。
module.exports = {
entry: './client/src/app.js',
devtool: '#eval-source-map',
output: {
path: __dirname + '/client/dist/',
filename: 'bundle.js'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|app-server.js)/,
loader: 'babel-loader'
}
]
}
};
npm install -g browserify
browserify ./client/src/app.js -o ./client/dist/bundle.js -t [ babelify --presets [ es2015 react ] ] -v