首页 > 解决方案 > Vue Js 2错误重新加载

问题描述

我正在使用 Vue Js 2 和 Nginx 服务器。

我有下一个代码:

const routes = [
   {
    path: '/design-dashboard',
    component: DesignDashboard,
    meta: {
        forAuth : true
    }
  },
  {
   path: '/dashboard/new/create',
    component: ProductLineEdit,
    meta: {
        forAuth : true
    }
  }
];

export default new VueRouter({
 mode: 'history',
 routes
});

问题是当 url 有超过 1 个斜杠 '/' 的部分时,例如它适用于“/design-dashboard”,而不适用于“/dashboard/new/create”,仅适用于 vue 路由器链接或 router.push() 方法,但是当我重新加载或尝试使用浏览器中的 url 直接访问时不起作用。

我还添加了这个 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>

正如我之前所说,只有一个部分或斜线'/ 例如“/design-dashboard”,一切正常

有任何想法吗?提前致谢。

标签: vue.jsvuejs2vue-router

解决方案


似乎您正在尝试配置htaccess用于apache.

尝试配置 nginx,配置如下:

location / {
  try_files $uri $uri/ /index.html;
}

推荐阅读