我有以下路由器配置:
const App = () => (
<HashRouter>
<div className="app">
<Switch>
<Route exact path="/" component={Landing} />
<Route exact path="/search" component={Search} />
<Route path="/details/:id" component={Details} />
<Route component={FourOhFour} />
</Switch>
</div>
</HashRouter>
)
当我加载http://localhost:8080/#/details/12345
时,我的组件详细信息正确呈现;
如果我切换到BrowserRouter,加载http://localhost:8080/details/12345
,我得到一个空白页面:index.html正确呈现,但我在控制台中收到以下错误:
拒绝申请样式 'http://localhost:8080/details/public/style.css'因为它的MIME类型 ('text / html')不是受支持的样式表MIME类型和严格的MIME 检查已启用。
GET http://localhost:8080/details/public/bundle.js 404(未找到)1:1
拒绝从执行脚本 'http://localhost:8080/details/public/bundle.js'因为它的MIME类型 ('text / html')不可执行,严格的MIME类型检查是 启用。
我正在关注在线课程,我正在使用webpack,我认为我的所有配置都与课程中的配置相同,课程视频中的应用程序正常工作
我的webpack.config.js如下:
const path = require('path')
const webpack = require('webpack')
module.exports = {
context: __dirname,
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
'./js/ClientApp.jsx'
],
devtool: process.env.NODE_ENV === 'development' ? 'cheap-eval-source-map' : false,
output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js',
publicPath: 'public/'
},
devServer: {
hot: true,
publicPath: '/public/',
historyApiFallback: true
},
resolve: {
extensions: ['.js', '.jsx', '.json']
},
stats: {
colors: true,
reasons: true,
chunks: true
},
plugins: [new webpack.HotModuleReplacementPlugin(), new webpack.NamedModulesPlugin()],
module: {
rules: [
// {
// enforce: 'pre',
// test: /\.jsx?$/,
// loader: 'eslint-loader',
// exclude: /node_modules/
// },
{
test: /\.jsx?$/,
loader: 'babel-loader'
}
]
}
}