vue.js - 找不到Vue js路由404和资产
问题描述
我已将模式设置为历史记录:
const router = new VueRouter({
mode: 'history',
routes:[
...
{
path: '*',
name: '404',
components: { default: Page404},
}
})
创建 htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
一切都按预期工作,错误的 url 落入 404 页面...问题在于深层 url,例如 website.com/wrong/wrong/wrong 图像没有出现在 404 页面中!
解决方案
/
好吧,这与我错过了在一级 url 上工作的斜线无关:
<img class="title" src="img/sad404.png" alt="404 not found" />
这是正确的方法:
<img class="title" src="/img/sad404.png" alt="404 not found" />
推荐阅读
- python - Python异步函数中断时如何实现最终清理?
- visual-studio-code - 如何从 VSCode 扩展中恢复意外删除的键盘快捷键?
- javascript - 在 foreach 循环中将类添加到具有 ID 的每个元素
- selenium-webdriver - Selenium 测试在 Jenkins 中失败,但不是在本地,因为焦点没有被触发
- r - 使用 R 中的循环创建 50 多个国家/地区的地块
- haskell - 如何更新用 Maybe 定义的 Data 属性
- python - 仅在特定点工作的两个图像之间使用蒙版的碰撞
- flutter - 无法使用 Flutter Dio multipartFile 上传文件
- reactjs - 如何使用 Modular Web SDK 版本 9 获取 Cloud Firestore 集合中的所有文档?
- javascript - 如何在 Flutter 移动应用上显示 Web iframe