![](/img/trans.png)
[英]Can't get userID route parameter to work on react-router-relay
[英]React Router - Stylesheet getting marked as "text/html" when adding a variable route (/:userId)
我們的自定義樣式表“styles.css”被錯誤的 MIME 類型“text/html”標記,甚至認為它有:
rel="stylesheet" type="text/css"
此錯誤僅在使用諸如 /:userId 之類的可變參數進行路由時發生
確切的錯誤是:
樣式表http://localhost:3000/user/static/styles/styles.css未加載,因為其 MIME 類型“text/html”不是“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 中,我的路徑從靜態開始缺少斜杠。
<link rel="stylesheet" type="text/css" href="static/styles/styles.css">
到
<link rel="stylesheet" type="text/css" href="/static/styles/styles.css">
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.