2016-02-05 79 views
1

angular2之前,如果我們想要得到直接從瀏覽器angularJS的路線,可以說我們使用hashbang辦法(​​)這樣的signup路線 - www.example.com/#/signup直接訪問從瀏覽器angular2路線打破

但與angular2這劑量工作。 我只能訪問註冊路線,直接點擊索引路線上的註冊按鈕 - www.example.com/

我已經添加了<base href="/">

請想知道我可以如何直接從瀏覽器url欄訪問註冊路線。謝謝。

回答

1

它的工作原理。您必須在應用中定義您的位置策略。

import {ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy } from "angular2/router"; 
bootstrap(AppComponent, [ 
ROUTER_PROVIDERS, 
... 
bind(LocationStrategy).toClass(HashLocationStrategy) 
]); 

所以,如果你想使用的URL以#,你的策略是HashLocationStrategy

+0

好感謝。但現在我想要吃我的蛋糕並且仍然吃它。是否有可能通過刪除哈希包來美化網址,並仍然像「www.example.com/signup」而不是「www.example.com /#/ signup」一樣擊中路線。 – oreofeolurin

+1

是的,那是PathLocationStrategy,有很多關於這個溢出的東西。 –