很有可能是在配置路由的时候随着链接的跳转,找不到之前的样式了。因此要看一下写的链接有没有问题,大概有以下三种解决方法:
- public/index.html 中引入样式时不写 ./ 写 /
<link rel="stylesheet" href="./css/bootstrap.css" />
改为
<link rel="stylesheet" href="/css/bootstrap.css" />
- public/index.html 中引入样式不写 ./ 写 %PUBLIC_URL%
<link rel="stylesheet" href="%PUBLIC_URL%/css/bootstrap.css" />
- 用HashRouter代替BrowerRouter
本文针对在配置路由过程中遇到的样式丢失问题提供了三种有效解决方案:调整public/index.html中的样式引入路径,使用%PUBLIC_URL%替代相对路径,以及采用HashRouter替换BrowerRouter。
1812

被折叠的 条评论
为什么被折叠?



