如何在angular2中通过打字稿更改路由器? [英] How to change router by typescript in angular2?
本文介绍了如何在angular2中通过打字稿更改路由器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
例如,我使用如下所示的router-link:
For example, I use router-link like this:
<li><a [router-link]="['/start']">Start</a></li>
但是如何将路由器更改为/start by typescript?
But how can I change the router to /start by typescript?
推荐答案
与哈希定位策略有关的小更新.
Small update related to hash location strategy.
在angular2的最新版本中,不建议使用bind
方法,因此您可以使用provide
方法来更改位置策略.
In recent versions of angular2 the bind
method is deprecated so you can change location strategy by using provide
method.
bootstrap(MyApp, [
ROUTER_PROVIDERS,provide(LocationStrategy, {useClass: HashLocationStrategy})
]);
这篇关于如何在angular2中通过打字稿更改路由器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文