2017-03-01 84 views
1

我正在使用ng-viewport在index.html中顯示我的頁面,在HTML 5模式下,當我們打開基礎URL(例如http://localhost:86)時,一切正常工作,並轉到(http://localhost:86/app/dashboard)這是我的家或着陸頁,並且所有其他重新方向正常工作。HTML 5模式深層鏈接和刷新不工作AngularJS

問題出現在我們直接嘗試打開完整的URL(例如http://localhost:86/app/dashboard)時,它正在加載我的index.html頁面,但只顯示靜態內容(如徽標和圖像),並且未顯示我的動態網頁在ng-viewport部分中顯示。在重新加載任何頁面時都有相同的行爲。

以下是我寫的代碼。

JS代碼。

$locationProvider.html5Mode({ enabled: true });

HTML代碼

<head> 
    <base href="/"/> 
</head> 
<body> 
    <div> 
     <img class="rotate" src="../assets/img/logo_img.png" /> 
    </div> 
    <div style="height: 100%" ng-viewport autoscroll> 
    </div> 
</body> 

的Web.Config

<?xml version="1.0" encoding="UTF-8"?> 
<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> 
    <security> 
     <requestFiltering> 
     <hiddenSegments> 
      <remove segment="App_Data" /> 
     </hiddenSegments> 
     </requestFiltering> 
    </security> 
    <rewrite> 
     <rules> 
     <clear /> 
     <rule name="AngularJS" enabled="true"> 
      <match url=".*" /> 
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false"> 
       <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /> 
       <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /> 
       <add input="{REQUEST_URI}" pattern="^/(Api)" negate="true" /> 
      </conditions> 
      <action type="Rewrite" url="/" /> 
     </rule> 
     </rules> 
    </rewrite> 
</system.webServer> 

路由配置代碼

static $routeConfig = [{ 
     path: '/dashboard/:type', 
     component: 'dashboard' 
    }, { 
     path: '/dashboard', 
     component: 'dashboard' 
    }, { 
     path: '/mail', 
     component: 'mail' 
    }, { 
     path: '/solution/:id', 
     component: 'solutionDetails' 
}] 

回答

0

該問題與我的js和css文件的相對路徑和絕對路徑有關。 我已經在我所加載的index.html中的所有文件路徑前面添加了/,現在一切都像魅力一樣。

**Earlier :** <script src="app.js"></script> 

**Now:** <script src="/app.js"></script>