我们的自定义样式表“styles.css”被标记为错误的 MIME 类型“text/html”,甚至认为它有:
rel="stylesheet" type="text/css"
此错误仅在使用可变参数(如/:userId)进行路由时发生
准确的错误是:
The stylesheet http://localhost:3000/user/static/styles/styles.css was not loaded because its MIME type, “text/html”, is not “text/css”.
路由器代码:
ReactDom.render(
<Router history={browserHistory}>
<Route component={MainLayout}>
<Route path="/" component={App} />
<Route path="/main" component={Home} />
<Route path="/user/:userId" component={UserSetting} />
</Route>
</Router>,
document.querySelector('.container')
);
这可能只是我需要在我们的快速服务器上考虑的一些配置吗?
最佳答案
事实证明这是我的一个简单疏忽。在我的 index.html 中,我从 static 开始的路径缺少斜线。
<link rel="stylesheet" type="text/css" href="static/styles/styles.css">
到
<link rel="stylesheet" type="text/css" href="/static/styles/styles.css">
关于javascript - React Router - 添加变量路由时样式表被标记为 "text/html"(/:userId),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39863781/