小编JAY*_*AYC的帖子

由于 MIME 类型不匹配,react.js 与 webpack 资源被阻止

使用 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\n
function 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}\n
Run Code Online (Sandbox Code Playgroud)\n\n

Webpack.config.js

\n\n
const 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)

reactjs webpack react-router

5
推荐指数
1
解决办法
5222
查看次数

标签 统计

react-router ×1

reactjs ×1

webpack ×1