首页 > 解决方案 > 角路线和子路线

问题描述

我有一个具有 2 个功能 useeRole1 和 uderRole2 的应用程序。在我的 userRole1 app.Routing 中,我已经声明了路由,例如 route1/subroute1 和 route1/subroute2。我有一个对应于 route1/subroute1 的页面,在这个页面中我想放置一个链接来访问 route1/subroute2。我在 html 中放什么来访问这个轮子

标签: angularroutes

解决方案


有两种方法可以实现它:

  1. 使用路由器链接:

    <a routerLink="['../subroute2']">SubRoute2</a>
    
  2. 以编程方式:

    <a href="javascript:void(0)" (click)="navToSubRoute()">SubRoute2</a>
    

    现在在您的组件中:

    navToSubRoute() {
       this.router.navigate(['route1', 'subroute2']);
    }
    

推荐阅读