如何在IIS服务器上配置Vue 2应用程序?

问题描述 投票:0回答:2

我需要配置 IIS 服务器和 Vue 2 应用程序的帮助,我刚刚安装了

vue 2 application
,并在
Windows IIS 7 server
上进行了生产构建,并且一切正常,只有一件事不起作用: 当我尝试打开任何带有用 vue-router 编写的链接“
example mysite.com/somepage
”的页面时,我看到
404 error
,但是如果我单击菜单链接工作正常,如果您只输入主 url mysite.com 它将打开,但是任何其他路线都不起作用!

我想我需要设置我的 httpRedirect 或类似的东西!

iis-7 vuejs2 windows-server-2008 vue-router
2个回答
13
投票

根据您的信息,我假设您使用的是

history
模式,这是我一直在使用的模式,您可以在 here 上参考:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Handle History Mode and custom 404/500" stopProcessing="true">
          <match url="(.*)" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

11
投票

vue-router文档中所述,为了使用历史模式,您需要执行以下操作:

  1. 安装 IIS UrlRewrite。
  2. 将 web.config 文件拖放到项目的根目录中。有关示例 web.config 文件,请参阅 vue-router 文档
© www.soinside.com 2019 - 2024. All rights reserved.