单页应用history路由刷新404问题解决方法

769 阅读1分钟

nginx config

server {
    listen 80xx;
    server_name _;
    index  index.html;
    root /xxx/www/project/;
    location / {
        try_files $uri $uri/ /index.html;
    }
}

IIS config

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <defaultDocument>
      <files>
        <clear />
        <add value="index.html" />
        <add value="Default.htm" />
        <add value="Default.asp" />
        <add value="index.htm" />
        <add value="iisstart.htm" />
        <add value="default.aspx" />
      </files>
    </defaultDocument>
    <rewrite>
      <rewriteMaps>
        <rewriteMap name="singlepage" />
      </rewriteMaps>
      <rules>
        <rule name="single-page-route" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" logRewrittenUrl="false" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>