【发布时间】:2017-12-13 13:05:25
【问题描述】:
我通过@NgModule 设置了路由配置。而且我有一项服务,可以根据某些条件确定应向用户显示应用程序的哪些部分。我需要调用该服务并根据返回的值设置路由。
问题:路由配置是在注解中设置的,我不知道如何在这样的设置中调用服务。
这里更具体地说是我要增强的示例配置。
我当前的路由设置:
const appRoutes: Routes = [
{
path: '',
redirectTo: 'first-route',
pathMatch: 'full'
},
{
path: 'first-route',
component: FirstComponent,
pathMatch: 'full'
},
{
path: 'second-route',
component: SecondComponent,
pathMatch: 'full'
},
...
];
@NgModule({
imports: [RouterModule.forChild(appRoutes)],
exports: [RouterModule]
})
export class MyRoutingModule {
}
应该改变路由设置的服务:
@Injectable()
export class MyService {
getAccessibleRoutes(): Observable<string[]> {...}
}
问题:如何拨打服务电话并更改路线?
注意:我也查看了"Dynamically adding routes in Angular" 和"How we can add new routes dynamically into RouterModule(@NgModule imports)",但我还没有找到明确的答案。
【问题讨论】:
标签: javascript angular typescript angular-ui-router url-routing