Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.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 react路由器和webpack似乎产生了错误的输出,在某些URL中给出了404_Javascript_Reactjs_Webpack_React Router Dom - Fatal编程技术网

Javascript react路由器和webpack似乎产生了错误的输出,在某些URL中给出了404

Javascript react路由器和webpack似乎产生了错误的输出,在某些URL中给出了404,javascript,reactjs,webpack,react-router-dom,Javascript,Reactjs,Webpack,React Router Dom,我得到了这个错误 GET http://localhost:9000/home/index.js 404 (Not Found) Refused to execute script from 'http://localhost:9000/home/index.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled. 当我使用react router d

我得到了这个错误

GET http://localhost:9000/home/index.js 404 (Not Found)
Refused to execute script from 'http://localhost:9000/home/index.js' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.
当我使用
react router dom
尝试不同的URL时。例如,像这样的URL

http://localhost:9000/home/x or http://localhost:9000/home/
但是当提供URL时,比如

http://localhost:9000/home
我得到了预期的输出。 这是
webpack.config.js

const HtmlWebPackPlugin = require("html-webpack-plugin");

var config = {
   mode:'none',
   entry: './main.js',
   output: {
      path:__dirname+'/',
      filename:'index.js',
      publicPath: '/'
   },
   devServer: {
      inline: true,
      historyApiFallback:true,
      contentBase: './',
      port: 9000
   },
   plugins: [
    new HtmlWebPackPlugin({
      template: __dirname+"/index.html"

    })
   ],
   module: {
      rules: [
         {
            test: /\.(js|jsx)$/,
            exclude: /node_modules/,
            use:{
               loader: 'babel-loader',
               query: {
                   presets: ['env', 'react']
               }
            },

         }
      ]
   },
}
module.exports = config;
这是路由器文件

export default class MainBody extends React.Component{
  render(){
    return(
      <Switch>
        <Route exact path='/' component={Home}/>
        <Route path ='/addticket' component={AddTicket}/>
        <Route path ='/profile' component={ProfileBox}/>
        <Route path ='/login' component={LoginForm}/>
        <Route path = '/newhome' component={NewHome}/>
        <Route component={NotFound}/>
      </Switch>
    );
  }
}
稍后使用
react dom
的渲染方法渲染。 我对代码的期望是,除了上面提到的URL之外,当给定URL时,
NotFound
组件的呈现。但是它在URL中给出了上面提到的错误,这些错误与下面的不同

http://localhost:9000/anything
这是package.json文件

"main": "main.js",
  "scripts": {
    "start": "webpack-dev-server --hot"
  },
  "license": "MIT",
  "peerDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "extract-text-webpack-plugin": "^3.0.2",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.2.0",
    "react": "^16.4.1",
    "react-bootstrap": "^0.32.1",
    "react-dom": "^16.4.1",
    "react-router-dom": "^4.3.1",
    "webpack": "^4.16.2",
    "webpack-dev-server": "^3.1.5"
  },
  "devDependencies": {
    "webpack-cli": "^3.1.0"
  }

react路由器的版本是什么?react路由器dom:4.3.1
"main": "main.js",
  "scripts": {
    "start": "webpack-dev-server --hot"
  },
  "license": "MIT",
  "peerDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.5",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "extract-text-webpack-plugin": "^3.0.2",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.2.0",
    "react": "^16.4.1",
    "react-bootstrap": "^0.32.1",
    "react-dom": "^16.4.1",
    "react-router-dom": "^4.3.1",
    "webpack": "^4.16.2",
    "webpack-dev-server": "^3.1.5"
  },
  "devDependencies": {
    "webpack-cli": "^3.1.0"
  }