找不到Vue JS路由404和资产

时间:2019-12-25 04:22:08

标签: vue.js vuejs2

我已将模式设置为历史记录:

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页...问题出在深网址上,例如website.com/wrong/wrong/wrong图片没有出现在404页中!

1 个答案:

答案 0 :(得分:0)

好吧,这与我缺少斜线/无关 这适用于一级网址:

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

这是正确的方法:

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