简体   繁体   English

Angular2路由:(为什么)我需要_指定LocationStrategy?

[英]Angular2 routing: (why) do I _need_ to specify LocationStrategy?

I've been having a hard time getting routing to work in Angular2. 我一直很难让路由在Angular2中工作。 Then I tried John Papas "Angular2-go" starter, and routing worked straight away. 然后,我尝试了John Papas的“ Angular2-go”启动器,并且路由选择立即起作用。 After some comparing/diffing, it turns out the only thing I was missing was the "provide(LocationStrategy, {useClass: HashLocationStrategy})" during bootstrap! 经过一些比较/差异后,发现我唯一缺少的是引导过程中的“ provide(LocationStrategy,{useClass:HashLocationStrategy})”!

bootstrap(AppComponent, [
ROUTER_PROVIDERS,
provide(LocationStrategy, {useClass: HashLocationStrategy})]);

Do we always need to specify this? 我们是否总是需要指定这个? What options are there? 有哪些选择? I found numerous examples that didn't include this, are they just outdated or am I missing something? 我发现了很多包含此示例的示例,它们只是过时了还是我缺少某些内容? I found nothing in the docs so far... 到目前为止,我在文档中都找不到任何内容...

See this issue . 看到这个问题 At this moment the default location strategy is PathLocationStrategy (see source codes here ), which requires some server tuning from you. 目前,默认的位置策略是PathLocationStrategy (请参见此处的源代码 ),这需要您对服务器进行一些调整。 But it looks like the situation can be changed in the future. 但是看起来情况将来会改变。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM