此時URL的改變已經完全不受后台代碼控制了,因此我們要在前端的ionic這個框架和IIS中進行修改調控。
其實IIS只是host了整個站點,具體的URL跳轉都是由前端來控制的。
1):那么前端要加上一行代碼:
$locationProvider.html5Mode(true);
2):IIS對應的web.config要做如下處理,是每次經過IIS的請求都跳回主頁,那么后續的URL管理都由前台框架來管理了:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="Main Rule" 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>
3):要保證上述config能夠生效,需要安裝IIS URL Rewrite的插件,具體下載地址如下所示:
http://www.iis.net/downloads/microsoft/url-rewrite
更多詳細的信息請看如下鏈接:
https://github.com/angular-ui/ui-router/wiki/Frequently-Asked-Questions#how-to-configure-your-server-to-work-with-html5mode