typescript Angular4 - 带有打字稿的 routerLink

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45625147/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:48:26  来源:igfitidea点击:

Angular4 - routerLink with typescript

javascriptangulartypescript

提问by ussefshahid

I have worked with routerLink and it works very well :

我曾与 routerLink 合作过,效果很好:

      <a routerLink="inscription" class="btn btn-default">Inscription</a>
      <a routerLink="login" class="btn btn-default">Se connecter</a>

I am trying now to deal with routerLinkinside the typescript file. Exactly, when i click on a button, i call a function inside this function i want to call routerLinkhow could i do it? and if is calling it will reload the page or it will work exactly the same as the routerLinkabove ?

我现在正在尝试处理routerLink打字稿文件。确切地说,当我点击一个按钮时,我在这个函数中调用了一个函数,我想调用routerLink我该怎么做?如果调用它会重新加载页面还是会与routerLink上面的完全相同?

采纳答案by Jorawar Singh

try this

试试这个

<a javascript:void(0) routerLink="inscription" class="btn btn-default">Inscription</a>

回答by DeborahK

In code, you use .navigate instead:

在代码中,您使用 .navigate 代替:

this.router.navigate(['/products']);

You pass it the same parameter as you do the routerLink.

您传递给它的参数与传递routerLink.

enter image description here

在此处输入图片说明