假設部署到根目錄下app文件夾里,則需要修改三處配置:
1、config => index.js
// Paths assetsRoot: path.resolve(__dirname, "../dist"), assetsSubDirectory: "static", assetsPublicPath: "/app/", //修改打包后路徑 修改這里
把 assetsPublicPath: "/", 修改成 assetsPublicPath: "/app/",
2、router => index.js
const router = new Router({ mode: "history", // base: getAbsolutePath(), base: "/app/", routes: [...] ......
增加基礎路徑 base:"/app/"
3、網站根目錄文件夾下修改配置文件,用的是IIS
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <defaultDocument> <files> <clear /> <add value="zkpt.asmx" /> <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> <!-- 刷新白屏增加配置start --> <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="/app/" /> </rule> </rules> </rewrite> </system.webServer> <!-- 刷新白屏增加配置end --> </configuration>
修改 <action type="Rewrite" url="/" />
為 <action type="Rewrite" url="/app/" />
這樣就可以了,親測沒有問題。
轉自:https://my.oschina.net/qingqingdego/blog/3006013