vue.js - 部署vue js应用程序并在路由中出现404错误

标签 vue.js

我正在使用简单的 webpack,但在将我的应用程序部署到托管服务器后,我的索引页面工作正常,但其他页面出现 404 错误。请我不知道是否有人知道发生了什么。简单的 webpack 仅生成构建 js 文件我就是这样,我的 dist 文件夹中没有 index.htm 文件c

最佳答案

I am going to show you how to do it but before read this from vue.js docs

Step 1 Run the following command


npm run build

Step 2 Copy the dist folder and put it in a new folder

Step 3 In the new folder create a new file and name it .htaccess

Step 4 Inside .htaccess file insert the following code


<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.html [L]
</IfModule>

Now you application is ready to deploy!You can even run it using apache on local machine.

Please again, read docs you can find more configurations there for nginx, node.js and learn more about all server configurations.



附加信息:我正在使用 laragon + apache,在第 4 步之后,我将新文件夹放入 www Laragon 的目录,并与 Laragon 一起使用。我想你可以通过将新文件夹放在 docs 中使用 xampp 或 wamp 来做同样的事情。目录。

关于vue.js - 部署vue js应用程序并在路由中出现404错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48752650/

相关文章:

javascript - 测试 Vue.js 过滤器

vue.js - 如何将 "key"指定为必需的 Prop ?

javascript - 如何在 Vuejs/Javascript 中使过滤器不区分大小写

playframework - 在 Play 框架应用程序中使用 Vue.js

vue.js - 如果满足某些条件,bootstrap-vue 复选框会阻止更改

javascript - VueJS 不存在对象的数据初始化

jquery - 在未显示的模式中加载/准备 jQuery

vue.js - 如何在使用 jest 测试 vuetify 组件时解决 'SyntaxError: Unexpected identifier'

javascript - Vue-Draggable & Acts As List - 如何更新整个列表位置?

javascript - 使用 promise 从数据库中获取身份值