2016-04-29 133 views
0

是否可以編輯散列表中hashtag的位置從/#//#在角度UI路由中編輯'哈希URL'

html5mode不支持(在舊的瀏覽器IE9和下),我得到hash URL/hashbang模式

我得到什麼:

'index.com/#/path/id' 

我希望得到什麼:

'index.com/path/#id' 

是否可以在角度應用程序配置中編輯hash-tag的URL /位置?或者是我想要一個哈希模式的未接受/無效的URL?

回答

0

在你的路由器頁面

$locationProvider.html5Mode(true); 
+0

「當不支持html5mode(在舊的瀏覽器IE9,下),我得到 '哈希URL'/ hashbang模式」 –

+0

儘管此代碼可能會回答此問題,但如果提供 關於_why_和/或_how_的附加上下文,則回答問題將顯着提高其長期值 。請[編輯]你的答案,添加一些解釋。 –

0

添加此代碼在不支持history API的瀏覽器無法從URL中移除#

From AngularJS Doc,當mode=truehtml5Mode:啓用

- {boolean} - (default: false)如果爲true,將依靠 history.pushState以變更網址,在那裏的支持。在不支持pushState的瀏覽器中將回退到 hash-prefixed路徑。

From $locationProvider source code,如果history.pushState失敗,它恢復舊的URL值:

function setBrowserUrlWithFallback(url, replace, state) { 
     var oldUrl = $location.url(); 
     var oldState = $location.$$state; 
     try { 
     $browser.url(url, replace, state); 

     // Make sure $location.state() returns referentially identical (not just deeply equal) 
     // state object; this makes possible quick checking if the state changed in the digest 
     // loop. Checking deep equality would be too expensive. 
     $location.$$state = $browser.state(); 
     } catch (e) { 
     // Restore old values if pushState fails 
     $location.url(oldUrl); 
     $location.$$state = oldState; 

     throw e; 
     } 
    } 
+0

我不想刪除它,我想在URL中編輯它的位置,就像我發佈的示例中那樣。 'index.com/path/#id' –

+0

'#'將被附加在基本URL之後。您的基本網址是「index.com」。我不認爲有可能實現'index.com/path /#id'。 –