2016-03-10 69 views
0

我有一個使用UI路由器的Angular APP。Angular UI路由器請求URL

.config(function($stateProvider) { 

    $stateProvider 
     .state('blog', { 
      url: '/blog', 
      templateUrl: 'assets/javascript/blog/blog.html', 
      controller: 'BlogCtrl', 
      controllerAs: 'vm' 
     }) 
}); 

如果我按與ui-sref="blog"鏈接,應用程序加載的博客觀點,但如果我在一個新的標籤MYAPP /博客打開,它trows我404錯誤。

Ps。我使用的是HTML5模式刪除/#/

更新:

我對每條路線單獨的文件,在app.js我用

.config(function($stateProvider, $urlRouterProvider, $locationProvider) { 

    $urlRouterProvider.otherwise('home'); 
    $locationProvider.html5Mode(true); 
}); 

而且具有在<base href="/"><head />

我做錯了什麼? 有人可以解釋一下嗎?

+0

你能說明你在哪裏使用了html5模式嗎? – v1shnu

+0

更新答案,檢查 – Hiero

+0

你是否在你的index.html頁面中指定了'base' url? – v1shnu

回答

3

爲了在刷新/重新加載上工作,您需要正確設置.htaccess文件或類似於您的根目錄並啓用重寫引擎。

這樣的事情應該工作。

RewriteEngine On 
# If an existing asset or directory is requested go to it as it is 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR] 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d 
RewriteRule^- [L] 

# If the requested resource doesn't exist, use index.html 
RewriteRule^/index.html