首页 文章

Angular2路由器:按路由名称而不是url模式导航

提问于
浏览
1

我正在寻找一种方法来使用名称导航到我的应用程序的路由,如Angular UI路由器 .

例如 :

const routes = [ { path: '/detail/:id', name: 'userDetail', component: DetailComponent } ]

<a [routerLink]=['userDetail', {id: user.id}]>Detail</a>

代替 :

<a [routerLink]=['/detail', user.id]>Detail</a>

这样,如果我想将路径从/ detail /:id更改为/ user /:id,我只需编辑路由配置文件,而不是编辑包含指向详细路径的链接的所有模板 .

可能吗 ?

谢谢,V .

1 回答

  • 0

    这就是我在角度4中实现它的方法,我认为它在2中的工作方式相同 .

    <button class='button' routerLink='"acquisition" + {{someValue}}'>
    

相关问题