使用 webpack 开发一个 React 应用程序,在我的 app.js 路由器中,当我将路由指定为 /foo 时,组件正常渲染,但是当我将路由指定为 /foo/bar 时,我收到以下错误\n“来自 \xe2 的资源\x80\x9c http://localhost:9000/foo/bar/bundle.js \xe2\x80\x9d 由于 MIME 类型 (\xe2\x80\x9ctext/html\xe2\x80\x9d) 不匹配 (X -内容类型选项:nosniff)”
\n\n应用程序.js
\n\nfunction App() {\n return (\n <div className="App">\n <BrowserRouter>\n <Router history={history}>\n <Switch>\n <Route exact path="/api/login" component={Login} /> //gives error\n <Route exact path="/login" component={Login} /> //renders normally\n <Route component={Error} />\n </Switch>\n </Router>\n </BrowserRouter>\n </div>\n );\n}\nRun Code Online (Sandbox Code Playgroud)\n\nWebpack.config.js
\n\nconst path = require(\'path\');\nconst HtmlWebpackPlugin = require(\'html-webpack-plugin\');\n\n\nmodule.exports = {\n entry: path.resolve(__dirname, \'src/index\'),\n output:{\n path: path.resolve(__dirname, \'dist\'),\n filename: \'bundle.js\',\n },\n …Run Code Online (Sandbox Code Playgroud)