在数据库中存储角度路径

问题描述 投票:1回答:1

想检查一下我们如何在数据库中存储路由。例如

const routes: Routes = [
{
    path: 'url-of-component
    component: ABCComponent
}

我们如何将ABCComponent存储到mySQL DB中?或者,如何根据组件的路径解析组件(例如/component/abc.component.ts)

angular typescript
1个回答
0
投票

您可以使用resetConfig动态加载路由:

constructor(router:Router, http:HttpClient) {
    this.http.get('/routes').subscribe(t=> {
          this.router.resetConfig(t);
    });    
}

确保将任何动态加载的组件添加到app模块的entryComponents

entryComponents: [MyDynamicComponent,...]

或者,如果您拥有可以从数据库中检索的数组中的所有路径,则可以通过entryComponents数组将它们全部添加到providers,作为引导过程的一部分:

@NgModule({
    ...
    providers: [
        { provide: ANALYZE_FOR_ENTRY_COMPONENTS, multi: true, useValue: routes }
    ]
})
© www.soinside.com 2019 - 2024. All rights reserved.