2016-02-05 78 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,有很多关于这个溢出的东西。 –