CSS样式中断使用参数?—状态304未修改

React Router - CSS Styling BREAKS using params? - Status 304 Not Modified?

本文关键字:状态 未修改 参数 样式 中断 CSS      更新时间:2023-09-26

请帮忙。我有一切工作很好,注册页面工作很好,所以签到页面。然而,当我转到url route/user/3时,它会破坏我在react/redux应用程序的公共目录下的自定义CSS样式页面。my样式表不再被读取。只有引导样式。

当我查看chrome开发工具中的网络选项卡时,在我的其他路由上样式表以状态200发送,但当我试图访问带有斜杠的路由时,即/user/4,样式表以304 Not Modified…

ReactDOM.render(
  <Router history={browserHistory}>
    <Route path="/" component={App}>
      <IndexRoute component={App}></IndexRoute>
      <Route path="/user/:user" component={UserDashboard}></Route>
      <Route path="/signup" component={Signup} />
      <Route path="/signin" component={Signin} />
    </Route>
  </Router>
  ,
  document.getElementById('root')
);

我有同样的问题,我解决它改变链接到我的css文件

:

<link rel="stylesheet" href="./css/materialize.min.css">

解决方案是:(删除第一个点,所有运行正常)

<link rel="stylesheet" href="/css/materialize.min.css">

也许你的问题是其他…但是我和你有同样的问题

304是由于浏览器缓存。您可以通过浏览器设置清除缓存,也可以使用Ctrl+F5(windows)/Command + R(MacOS)强制刷新。

URL最好以/开头,这样它会返回你想要的URL,而不是它的父URL或子URL。

如果你正在浏览的URL是http://localhost:3000/user/johnny,那么你最终会得到以下链接,这取决于你是否在你的href中有正斜杠。

href="/css/bootstrap.min.css"变为http://localhost:3000/css/bootstrap.min.css

href="./css/bootstrap.min.css"变为http://localhost:3000/user/johnny/css/bootstrap.min.css