首页 > 解决方案 > 如何在 Angular2 路由中传递服务功能

问题描述

如何在路径中连接“TTENCommonService.getRole()”?在 getRole() 事件中,我返回了字符串值。

应用程序路由.module.ts

import { TTENCommonService } from './tten-common/services/tten- 
  common.service';

const routes: Routes = [
  {
    path: '', redirectTo: '/dashboard '+ TTENCommonService.getRole(), pathMatch: 'full'
  }
];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})

export class AppRoutingModule { }

标签: angularangular5angular2-routingangular2-servicesangular4-router

解决方案


因为是课外。你可以打电话给新的运营商。请看下面的代码。

希望能帮助到你。

const routes: Routes = [
  {
    path: '', redirectTo: '/dashboard '+ new TTENCommonService().getRole(), pathMatch: 'full'
  }
];

推荐阅读