首页 > 解决方案 > 找不到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 页面中!

标签: vue.jsvuejs2

解决方案


/ 好吧,这与我错过了在一级 url 上工作的斜线无关:

<img class="title" src="img/sad404.png" alt="404 not found" />

这是正确的方法:

<img class="title" src="/img/sad404.png" alt="404 not found" />

推荐阅读