【发布时间】:2016-05-06 20:55:11
【问题描述】:
我的 routes.js 设置如下:
<Route path="users" component={requireAuth(users)} />
<Route path="user-:id" component={requireAuth(userSelect)} />
一切正常,当我将破折号更改为正斜杠时,我唯一的问题出现了:
<Route path="user/:id" component={requireAuth(userSelect)} />
当我这样做时,我的 css 的 href 路径会发生变化,所以当我打开 www.siteexample.com/user/1 时,我会收到如下所示的 GET 错误:
GET http://siteexample.com/user/style/css/bootstrap.min.css
我的 index.html 看起来像这样:
<link href="style/css/bootstrap.min.css" rel="stylesheet">
似乎当添加正斜杠时,“用户”成为相对文件路径的根,并且反应路由器试图从那里找到 css 文件而不是 index.html 的位置。链接href实际上应该是
http://siteexample.com/style/css/bootstrap.min.css
有什么我可以添加到我的 href 以强制它进入我网站的主根目录的吗?
【问题讨论】:
-
你不能像 href="/style/css/bootstrap.min.css" 那样链接到你的css文件吗?
-
@nuway 成功了,谢谢!
-
不客气,请接受下面的回答
标签: react-router href relative-path