Vue Js 2错误重新加载

Posted

技术标签:

【中文标题】Vue Js 2错误重新加载【英文标题】:Vue Js 2 error reload 【发布时间】: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”

有什么想法吗?提前致谢。

【问题讨论】:

【参考方案1】:

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

尝试配置nginx,配置如下:

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

【讨论】:

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

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

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

【讨论】:

以上是关于Vue Js 2错误重新加载的主要内容,如果未能解决你的问题,请参考以下文章

页面重新加载和直接 url 上的 Vue 渲染错误

vue页面重新加载功能 - 错误

错误:加载 PostCSS 插件失败:令牌无效或意外(Vue.js、tailwind css)

html页面加载JS文件经常错误

由于异步 JSON 加载,Vue.js 错误 [渲染根实例时出错]

Vue.js 路由器错误:devtools-api 适当的加载器