我正在使用简单的 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/