Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 即使不使用路由器错误,也要对其作出反应_Javascript_Reactjs_React Router_React Router Dom - Fatal编程技术网

Javascript 即使不使用路由器错误,也要对其作出反应

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

我在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)
我建议你:

  • 删除build*.js文件
  • Check不是
    package.json
    文件中的
    react router dom
  • 如果是,则
    npm uninstall--保存react router dom
    在其他情况下删除
    node_模块
    目录,再次安装软件包,然后检查build
  • 您还可以尝试使用browserify构建测试代码:

    npm 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