【问题标题】:Vue Js 2 error reloadVue Js 2错误重新加载
【发布时间】:2018-10-14 03:05:44
【问题描述】:

我正在使用 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 个部分 o 斜杠“/”时,例如它适用于“/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.js vuejs2 vue-router


    【解决方案1】:

    您似乎正在尝试使用用于apachehtaccess 配置 nginx 服务器。

    尝试配置nginx,配置如下:

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

    【讨论】:

    • 我认为与 Vue 路由器中的“儿童”东西更相关
    【解决方案2】:

    我解决了这个问题,将 .htaccess 和转换添加到 nginx 代码并在脚本标记的 src 属性中添加斜杠“/”

     <script src="/dist/app.js">
    

    【讨论】:

      猜你喜欢
      • 2021-12-26
      • 1970-01-01
      • 2018-05-12
      • 2020-05-28
      • 2018-07-04
      • 1970-01-01
      • 2017-07-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多