{"id":1041,"date":"2023-03-12T09:55:12","date_gmt":"2023-03-12T01:55:12","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=1041"},"modified":"2023-04-29T12:42:33","modified_gmt":"2023-04-29T04:42:33","slug":"vue-set-routing-history-mode-and-package-after-vue-run-build-to-access-404-issues","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/03\/12\/vue-set-routing-history-mode-and-package-after-vue-run-build-to-access-404-issues\/","title":{"rendered":"Vue\u8bbe\u7f6e\u8def\u7531History mode\u6a21\u5f0f\uff0c\u6253\u5305vue run build\u540e\u8bbf\u95ee404\u95ee\u9898"},"content":{"rendered":"<h2>\u95ee\u9898\u63cf\u8ff0<\/h2>\n<p>Vue\u8bbe\u7f6e\u8def\u7531History mode\u6a21\u5f0f\uff0c\u6253\u5305<code>vue run build<\/code>\u540e\u9875\u9762\u8bbf\u95ee\u62a5404\u9519\u8bef\u3002\u4e00\u822c\u5f00\u53d1\u5355\u9875\u5e94\u7528\u7684URL\u90fd\u4f1a\u5e26\u6709#\u53f7\u7684hash\u6a21\u5f0f\uff0c\u56e0\u4e3a\u4e1a\u52a1\u9700\u6c42\uff0c\u6216\u8005\u4e0d\u60f3\u4f7f\u7528\u5e26#\u53f7\uff0c\u901a\u5e38\u5728\u8def\u7531index.js\u91cc\u9762\u8bbe\u7f6e\uff1a<\/p>\n<p><!-- more --><\/p>\n<pre><code class=\"language-javascript\">export default new Router({\n  \/\/ base: &#039;\/dist\/&#039;,\n  mode: &#039;history&#039;,<\/code><\/pre>\n<h2>\u89e3\u51b3\u65b9\u6cd5<\/h2>\n<p>\uff081\uff09Apache\u9700\u8981\u914d\u7f6ehttpd.conf<\/p>\n<p>\u5f00\u542fRewrite\uff1a<code>LoadModule rewrite_module modules\/mod_rewrite.so<\/code><\/p>\n<p>\u6587\u4ef6\u6700\u540e\u6dfb\u52a0\uff1a<code>ErrorDocument 404 \/index.html<\/code><\/p>\n<p>\uff082\uff09Nginx\u9700\u8981\u914d\u7f6e<\/p>\n<p>\u6839\u76ee\u5f55\uff1a<\/p>\n<pre><code>location @router {\n  rewrite ^.*$ \/index.html last;\n}\nlocation \/ {\n  try_files $uri $uri\/ @router;\n  index index.html;\n}<\/code><\/pre>\n<p>\u975e\u6839\u76ee\u5f55\uff1a<\/p>\n<pre><code>location @router {\n  rewrite ^.*$ \/dist\/index.html last;\n}\nlocation \uff5e\/dist\/.* {\n  try_files $uri $uri\/dist @router;\n  index index.html;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u95ee\u9898\u63cf\u8ff0 Vue\u8bbe\u7f6e\u8def\u7531History mode\u6a21\u5f0f\uff0c\u6253\u5305vue run build\u540e\u9875\u9762\u8bbf\u95ee\u62a5404\u9519\u8bef\u3002\u4e00 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-1041","post","type-post","status-publish","format-standard","hentry","category-vue"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1041","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=1041"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/1041\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=1041"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=1041"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=1041"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}