[英]React-router error even without using it
我在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
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)
我想知道那可能來自哪里。 我從編譯文件中完全刪除了它。
我使用webpack來編譯主要的響應文件,我將其修改為盡可能簡單,以便找出令人討厭的錯誤來自何處:
app.js
import ReactDom from 'react-dom';
const Error = () => <h1>Error</h1>;
ReactDom.render(
<Error/>
,
document.getElementById('react-app'));
所以我基本上不再在任何地方使用react-router-dom
了,但是由於某種原因,錯誤仍然存在。
Webpack配置:
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'
}
]
}
};
我建議你:
package.json
文件中選中Is not react-router-dom
。 npm uninstall --save react-router-dom
在其他情況下)刪除node_modules
目錄,再次安裝軟件包,然后檢查build。 您也可以嘗試使用Browserify構建代碼進行測試:
npm install -g browserify
browserify ./client/src/app.js -o ./client/dist/bundle.js -t [ babelify --presets [ es2015 react ] ] -v
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.